Documentation
¶
Overview ¶
Package hirevec implements internal server features
Index ¶
- Constants
- Variables
- func AuthAccessToken(w http.ResponseWriter, accessToken AccessToken)
- func AuthError(w http.ResponseWriter, code AuthErrorCode, description string)
- func AuthTokenPair(w http.ResponseWriter, tokenPair TokenPair)
- func BaseMiddleware(handler http.HandlerFunc) http.Handler
- func Chain(handler http.HandlerFunc, middlewares ...Middleware) http.HandlerFunc
- func CreateMeReaction(s StoreInterface) http.HandlerFunc
- func CreateOnboardingToken(v VaultInterface, w http.ResponseWriter, userID ULID, provider Provider)
- func CreateTokenPair(s StoreInterface, v VaultInterface, w http.ResponseWriter, userID ULID, ...)
- func DecodeRequestBody[T any](r *http.Request) (*T, error)
- func DeleteCookies(w http.ResponseWriter, names []string)
- func Error(w http.ResponseWriter, status int, message string)
- func Fail(w http.ResponseWriter, status int, data FailData)
- func FinishAuthFlow(s StoreInterface, v VaultInterface, w http.ResponseWriter, user User)
- func GenerateUsername() (string, error)
- func GetMeMatches(s StoreInterface) http.HandlerFunc
- func GetMeReactions(s StoreInterface) http.HandlerFunc
- func GetMeRecommendations(s StoreInterface) http.HandlerFunc
- func Health(w http.ResponseWriter, r *http.Request)
- func InitLogger(config LoggerConfig)
- func Logger(next http.HandlerFunc) http.HandlerFunc
- func MaxBytesLimiter(next http.HandlerFunc) http.HandlerFunc
- func NewServer(ctx context.Context, c ServerConfig, s StoreInterface, v VaultInterface) (*http.Server, error)
- func OAuthAuthorize(v VaultInterface) http.HandlerFunc
- func OAuthCallback(s StoreInterface, v VaultInterface) http.HandlerFunc
- func OAuthToken(s StoreInterface, v VaultInterface) http.HandlerFunc
- func PanicHandler(next http.HandlerFunc) http.HandlerFunc
- func ParseDurationWithDefault(value string, defaultValue time.Duration) time.Duration
- func ParseLogLevelWithDefault(value string, defaultValue slog.Level) slog.Level
- func ParseUint16WithDefault(value string, defaultValue uint16) uint16
- func ProtectedRoute(cfg RouteConfig, v VaultInterface)
- func PublicRoute(cfg RouteConfig)
- func RootMux(s StoreInterface, v VaultInterface) http.Handler
- func Route(method Method, route string) string
- func RunApp(c AppConfig) error
- func RunServer(ctx context.Context, c ServerConfig, s StoreInterface, v VaultInterface) error
- func SetAuthHeaders(w http.ResponseWriter)
- func SetDefaultHeaders(w http.ResponseWriter)
- func SetUnauthorizedHeaders(w http.ResponseWriter)
- func Success(w http.ResponseWriter, status int, res Resource)
- func Unauthorized(w http.ResponseWriter, code AuthErrorCode, description string)
- func ValidateAbout(about string) (string, error)
- func ValidateName(name string) (string, error)
- func WaitAndShutdown(ctx context.Context, server *http.Server, errCh chan error, ...) error
- func WriteJSON(w http.ResponseWriter, status int, data any)
- type AccessToken
- type AccessTokenClaims
- type AppConfig
- type AuthErrorCode
- type AuthErrorResponse
- type Candidate
- type CandidateRecommendation
- type ContextKey
- type Embedded
- type ErrorCode
- type ErrorResponse
- type FailData
- type FailResponse
- type IssuedTokenType
- type Link
- type Links
- type LoggerConfig
- type Match
- type Method
- type Middleware
- type OIDCConfig
- type Page
- type Position
- type PositionRecommendation
- type Props
- type Provider
- type Reaction
- type ReactionType
- type ReactorType
- type Recommendation
- type Recruiter
- type RefreshToken
- type RefreshTokenClaims
- type RelType
- type Resource
- type ResponseStatus
- type ResponseWriter
- type Role
- type RouteConfig
- type Scope
- type ScopeValue
- type ServerConfig
- type StateTokenClaims
- type StoreConfig
- type StoreImpl
- func (s StoreImpl) CreateCandidate(c Candidate) error
- func (s StoreImpl) CreateReaction(r Reaction) error
- func (s StoreImpl) CreateRecommendation(positionID, candidateID ULID) (ULID, error)
- func (s StoreImpl) CreateRecruiter(r Recruiter) error
- func (s StoreImpl) CreateRefreshToken(userID ULID, expiresAt time.Time) (jti ULID, err error)
- func (s StoreImpl) CreateUser(u User) (ULID, error)
- func (s StoreImpl) GetCandidate(id ULID) (*Candidate, error)
- func (s StoreImpl) GetCandidateByUserID(userID ULID) (*Candidate, error)
- func (s StoreImpl) GetCandidateRecommendations(recruiterID ULID, page Page, excludeReacted bool) ([]CandidateRecommendation, ULID, error)
- func (s StoreImpl) GetMatchesByCandidateID(candidateID ULID, page Page) (matches []Match, nextCursor ULID, err error)
- func (s StoreImpl) GetPosition(id ULID) (*Position, error)
- func (s StoreImpl) GetPositionRecommendations(candidateID ULID, page Page, excludeReacted bool) (positionRecommendations []PositionRecommendation, nextCursor ULID, err error)
- func (s StoreImpl) GetReactionsByCandidateID(candidateID ULID, page Page) (reactions []Reaction, nextCursor ULID, err error)
- func (s StoreImpl) GetRecommendation(id ULID) (*Recommendation, error)
- func (s StoreImpl) GetRecruiterByUserID(userID ULID) (*Recruiter, error)
- func (s StoreImpl) GetUserByProvider(provider Provider, providerUserID string) (ULID, map[Role]ULID, error)
- func (s StoreImpl) GetUserRoles(userID ULID, provider Provider) (map[Role]ULID, error)
- func (s StoreImpl) IsActiveSession(jti ULID) (bool, error)
- type StoreInterface
- type TokenPair
- type ULID
- type User
- type VaultConfig
- type VaultImpl
- func (v VaultImpl) CreateAccessToken(userID ULID, provider Provider, roles map[Role]ULID) (*AccessToken, error)
- func (v VaultImpl) CreateAuthCodeURL(state string, verifier string, provider Provider) (string, error)
- func (v VaultImpl) CreateRefreshToken(userID ULID, provider Provider, jti ULID) (*RefreshToken, error)
- func (v VaultImpl) CreateStateToken(provider Provider) (string, error)
- func (v VaultImpl) CreateTokenPair(userID ULID, provider Provider, jti ULID, roles map[Role]ULID) (*TokenPair, error)
- func (v VaultImpl) ExchangeAppleCodeForIDToken(ctx context.Context, code string, verifierCookie *http.Cookie) (string, error)
- func (v VaultImpl) ExchangeGoogleCodeForIDToken(ctx context.Context, code string, verifierCookie *http.Cookie) (string, error)
- func (v VaultImpl) ParseAccessToken(tokenString string) (*AccessTokenClaims, error)
- func (v VaultImpl) ParseRefreshToken(tokenString string) (*RefreshTokenClaims, error)
- func (v VaultImpl) ParseStateToken(raw string) (*StateTokenClaims, error)
- func (v VaultImpl) VerifyAndParseAppleIDToken(ctx context.Context, rawIDToken string, userJSON string) (*User, error)
- func (v VaultImpl) VerifyAndParseGoogleIDToken(ctx context.Context, rawIDToken string) (*User, error)
- type VaultInterface
Constants ¶
const ( DefaultReadTimeout = 2000 * time.Millisecond DefaultWriteTimeout = 2000 * time.Millisecond DefaultGracePeriod = 5000 * time.Millisecond DefaultPageSizeLimit = 50 PageSizeMaxLimit = 100 )
const ( RouteHealth = "/health" RouteOAuthToken = "/oauth/token" RouteOAuthAuthorize = "/oauth/authorize" RouteOAuthCallback = "/oauth/callback" RouteMeRecommendations = "/v1/me/recommendations" RouteMeReactions = "/v1/me/reactions" RouteMeMatches = "/v1/me/matches" RouteMeReaction = "/v1/me/recommendations/{id}/reaction" )
const ( DefaultRefreshTokenExpiration = 30 * 24 * time.Hour DefaultAccessTokenExpiration = 30 * time.Minute DefaultStateTokenExpiration = 10 * time.Minute DefaultVerifierExpiration = 10 * time.Minute DefaultProvider = ProviderGoogle )
const ( TokenAudience = "api.hirevec.com" TokenIssuer = "api.hirevec.com" StateTokenAudience = "oauth-state" )
const DefaultLogLevel = slog.LevelError
Variables ¶
var ( ErrAboutForbiddenChars = errors.New("about contains forbidden characters") ErrAboutTooLong = errors.New("about too long") ErrAboutTooShort = errors.New("about too short") ErrEmailNotVerified = errors.New("email not verified") ErrExtraDataDecoded = errors.New("extra data decoded") ErrFailedBindAddress = errors.New("failed to bind address") ErrFailedDecode = errors.New("failed to decode") ErrFailedGenerateUsernameSuffix = errors.New("failed to generate random username suffix") ErrFailedShutdownServer = errors.New("failed to shutdown server") ErrNameForbiddenChars = errors.New("name contains forbidden characters") ErrNameTooLong = errors.New("name too long") ErrNameTooShort = errors.New("name too short") ErrFailedCloseRequestBody = errors.New("failed to close request body") )
var ( ErrFailedConnectDB = errors.New("failed to connect to database") ErrFailedPingDB = errors.New("failed to ping database") ErrUserNoRole = errors.New("user has no role") ErrUserNotFound = errors.New("user not found") ErrRecommendationExists = errors.New("recommendation already exists") ErrCandidateNotFound = errors.New("candidate not found") ErrRecruiterNotFound = errors.New("recruiter not found") ErrReactionAlreadyExists = errors.New("reaction already exists") )
var ( ErrFailedSetScope = errors.New("failed to set scope") ErrFailedCreateAccessToken = errors.New("failed to create access token") ErrFailedCreateAppleOIDCProvider = errors.New("failed to create Apple OIDC provider") ErrFailedCreateGoogleOIDCProvider = errors.New("failed to create Google OIDC provider") ErrFailedCreateRefreshToken = errors.New("failed to create refresh token") ErrFailedExchangeToken = errors.New("failed to exchange tokens") ErrFailedLoadAsymmetricKey = errors.New("failed to load asymmetric key") ErrFailedLoadSymmetricKey = errors.New("failed to load symmetric key") ErrFailedParseClaims = errors.New("failed to parse claims") ErrFailedParseJTI = errors.New("failed to parse jti") ErrFailedParseProvider = errors.New("failed to parse provider") ErrFailedParseScope = errors.New("failed to parse scope") ErrFailedParseTokenType = errors.New("failed to parse token type") ErrFailedParseCSRF = errors.New("failed to parse CSRF") ErrFailedSetProvider = errors.New("failed to set provider") ErrFailedSetTokenType = errors.New("failed to set token type") ErrIDTokenRequired = errors.New("id_token required") ErrInvalidAccessToken = errors.New("invalid access token") ErrInvalidIDToken = errors.New("invalid id_token") ErrInvalidProvider = errors.New("invalid provider") ErrInvalidRefreshToken = errors.New("invalid refresh token") ErrInvalidRole = errors.New("invalid role") ErrInvalidSubject = errors.New("invalid subject") ErrInvalidTokenType = errors.New("invalid token type") ErrInvalidScopeValue = errors.New("invalid scope value provided") ErrInvalidStateToken = errors.New("invalid state token") )
Functions ¶
func AuthAccessToken ¶
func AuthAccessToken(w http.ResponseWriter, accessToken AccessToken)
func AuthError ¶
func AuthError(w http.ResponseWriter, code AuthErrorCode, description string)
func AuthTokenPair ¶
func AuthTokenPair(w http.ResponseWriter, tokenPair TokenPair)
func BaseMiddleware ¶
func BaseMiddleware(handler http.HandlerFunc) http.Handler
func Chain ¶
func Chain(handler http.HandlerFunc, middlewares ...Middleware) http.HandlerFunc
Chain wraps handler into a sequence of middlewares, each middleware is applied in the same order it is provided.
func CreateMeReaction ¶
func CreateMeReaction(s StoreInterface) http.HandlerFunc
Records a candidate's reaction to a position recommendation.
func CreateOnboardingToken ¶
func CreateOnboardingToken(v VaultInterface, w http.ResponseWriter, userID ULID, provider Provider)
func CreateTokenPair ¶
func CreateTokenPair(s StoreInterface, v VaultInterface, w http.ResponseWriter, userID ULID, provider Provider, roles map[Role]ULID)
func DeleteCookies ¶
func DeleteCookies(w http.ResponseWriter, names []string)
func FinishAuthFlow ¶
func FinishAuthFlow(s StoreInterface, v VaultInterface, w http.ResponseWriter, user User)
func GenerateUsername ¶
GenerateUsername creates username with a cryptographically random suffix
func GetMeMatches ¶
func GetMeMatches(s StoreInterface) http.HandlerFunc
Returns all mutual matches for the authenticated candidate.
func GetMeReactions ¶
func GetMeReactions(s StoreInterface) http.HandlerFunc
Returns all reactions made by the authenticated candidate.
func GetMeRecommendations ¶
func GetMeRecommendations(s StoreInterface) http.HandlerFunc
Returns position recommendations for the authenticated candidate.
func InitLogger ¶
func InitLogger(config LoggerConfig)
func Logger ¶
func Logger(next http.HandlerFunc) http.HandlerFunc
func MaxBytesLimiter ¶
func MaxBytesLimiter(next http.HandlerFunc) http.HandlerFunc
func NewServer ¶
func NewServer(ctx context.Context, c ServerConfig, s StoreInterface, v VaultInterface) (*http.Server, error)
func OAuthAuthorize ¶
func OAuthAuthorize(v VaultInterface) http.HandlerFunc
func OAuthCallback ¶
func OAuthCallback(s StoreInterface, v VaultInterface) http.HandlerFunc
func OAuthToken ¶
func OAuthToken(s StoreInterface, v VaultInterface) http.HandlerFunc
func PanicHandler ¶
func PanicHandler(next http.HandlerFunc) http.HandlerFunc
func ParseUint16WithDefault ¶
func ProtectedRoute ¶
func ProtectedRoute(cfg RouteConfig, v VaultInterface)
func PublicRoute ¶
func PublicRoute(cfg RouteConfig)
func RootMux ¶
func RootMux(s StoreInterface, v VaultInterface) http.Handler
func RunServer ¶
func RunServer(ctx context.Context, c ServerConfig, s StoreInterface, v VaultInterface) error
func SetAuthHeaders ¶
func SetAuthHeaders(w http.ResponseWriter)
func SetDefaultHeaders ¶
func SetDefaultHeaders(w http.ResponseWriter)
func SetUnauthorizedHeaders ¶
func SetUnauthorizedHeaders(w http.ResponseWriter)
func Unauthorized ¶
func Unauthorized(w http.ResponseWriter, code AuthErrorCode, description string)
func ValidateAbout ¶
func ValidateName ¶
func WaitAndShutdown ¶
Types ¶
type AccessToken ¶
type AccessTokenClaims ¶
type AppConfig ¶
type AppConfig struct {
Protocol string
Host string
Port string
RequestReadTimeout string
RequestWriteTimeout string
GracePeriod string
PostgresHost string
PostgresPort string
PostgresDB string
PostgresUser string
PostgresPassword string
LogLevel string
SymmetricKey string
AsymmetricKey string
GoogleClientID string
GoogleClientSecret string
AppleClientID string
AppleClientSecret string
}
type AuthErrorCode ¶
type AuthErrorCode string
AuthErrorCode defienes OAuth2 error codes, see [RFC6749](https://www.rfc-editor.org/rfc/rfc6749.txt).
const ( /* The request is missing a required parameter, includes an unsupported parameter value (other than grant type), repeats a parameter, includes multiple credentials, utilizes more than one mechanism for authenticating the client, or is otherwise malformed. */ AuthInvalidRequest AuthErrorCode = "invalid_request" /* The provided authorization grant (e.g., authorization code, resource owner credentials) or refresh token is invalid, expired, revoked, does not match the redirection URI used in the authorization request, or was issued to another client. */ AuthInvalidGrant AuthErrorCode = "invalid_grant" /* Client authentication failed (e.g., unknown client, no client authentication included, or unsupported authentication method). The authorization server MAY return an HTTP 401 (Unauthorized) status code to indicate which HTTP authentication schemes are supported. If the client attempted to authenticate via the "Authorization" request header field, the authorization server MUST respond with an HTTP 401 (Unauthorized) status code and include the "WWW-Authenticate" response header field matching the authentication scheme used by the client. */ AuthInvalidClient AuthErrorCode = "invalid_client" AuthUnauthorizedClient AuthErrorCode = "unauthorized_client" /* The authorization grant type is not supported by the authorization server. */ AuthUnsupportedGrantType AuthErrorCode = "unsupported_grant_type" )
type AuthErrorResponse ¶
type AuthErrorResponse struct {
Error AuthErrorCode `json:"error"`
ErrorDescription string `json:"error_description,omitempty"`
ErrorURI string `json:"error_uri,omitempty"`
}
AuthErrorResponse defines OAuth2 error response.
type Candidate ¶
type Candidate struct {
ID ULID `json:"id"`
UserID ULID `json:"user_id,omitempty"`
About string `json:"about"`
}
Candidate represents a candidate profile
type CandidateRecommendation ¶
type ContextKey ¶
type ContextKey string
const ( ContextKeyUserID ContextKey = "user_id" ContextKeyClaims ContextKey = "claims" )
type ErrorResponse ¶
type ErrorResponse struct {
Status ResponseStatus `json:"status"`
Message string `json:"message"`
Code ErrorCode `json:"code,omitempty"`
}
type FailData ¶
FailData defines [JSend](https://github.com/omniti-labs/jsend) request failure data.
type FailResponse ¶
type FailResponse struct {
Status ResponseStatus `json:"status"`
Data FailData `json:"data,omitempty"`
Links Links `json:"_links,omitempty"`
}
type IssuedTokenType ¶
type IssuedTokenType string
const ( IssuedTokenTypeRefreshToken IssuedTokenType = "urn:ietf:params:oauth:token-type:refresh_token" IssuedTokenTypeAccessToken IssuedTokenType = "urn:ietf:params:oauth:token-type:access_token" )
type Link ¶
type Link struct {
Href string `json:"href"`
Name string `json:"name,omitempty"`
Templated bool `json:"templated,omitempty"`
}
Link defines a [HAL](https://datatracker.ietf.org/doc/html/draft-kelly-json-hal-11) link object.
type LoggerConfig ¶
type Middleware ¶
type Middleware func(http.HandlerFunc) http.HandlerFunc
func Authentication ¶
func Authentication(v VaultInterface, allowedRoles []Role) Middleware
type OIDCConfig ¶
type OIDCConfig struct {
OAuth2Config *oauth2.Config
Verifier *oidc.IDTokenVerifier
}
type Page ¶
type Page struct {
Cursor string `json:"cursor,omitempty"`
Limit int `json:"limit"`
Count int `json:"count"`
HasNext bool `json:"has_next"`
}
func GetPagination ¶
type Position ¶
type Position struct {
ID ULID `json:"id"`
RecruiterID ULID `json:"recruiter_id"`
Title string `json:"title"`
Description string `json:"description"`
Company string `json:"company"`
}
Position represents a job position
type PositionRecommendation ¶
type Reaction ¶
type Reaction struct {
RecommendationID ULID `json:"recommendation_id"`
ReactorType ReactorType `json:"reactor_type"`
ReactorID ULID `json:"reactor_id"`
ReactionType ReactionType `json:"reaction_type"`
ReactedAt time.Time `json:"reacted_at"`
}
Reaction represents either a candidate or recruiter reaction to a recommendation
type ReactionType ¶
type ReactionType string
const ( ReactionTypePositive ReactionType = "positive" ReactionTypeNegative ReactionType = "negative" ReactionTypeNeutral ReactionType = "neutral" )
func (ReactionType) IsValid ¶
func (r ReactionType) IsValid() bool
type ReactorType ¶
type ReactorType string
const ( ReactorTypeCandidate ReactorType = "candidate" ReactorTypeRecruiter ReactorType = "recruiter" )
func (ReactorType) IsValid ¶
func (r ReactorType) IsValid() bool
type Recommendation ¶
type RefreshToken ¶
type RefreshTokenClaims ¶
type RelType ¶
type RelType string
RelType defines link relation type, see [RFC5988](https://www.rfc-editor.org/rfc/rfc5988.txt).
const ( // All went well, and (usually) some data was returned. ResponseStatusSuccess = "success" // There was a problem with the data submitted, or some pre-condition of the API call wasn't satisfied. ResponseStatusFail = "fail" // An error occurred in processing the request, i.e. an exception was thrown. ResponseStatusError = "error" // Conveys an identifier for the link's context. RelTypeSelf RelType = "self" // Refers to a parent document in a hierarchy of documents. RelTypeUp RelType = "up" // Refers to the previous resource in an ordered series of resources. RelTypePrevious RelType = "previous" // Refers to the next resource in a ordered series of resources. RelTypeNext RelType = "next" // An IRI that refers to the furthest preceding resource in a series of resources. RelTypeFirst RelType = "first" // An IRI that refers to the furthest following resource in a series of resources. RelTypeLast RelType = "last" // Refers to an index. RelTypeIndex RelType = "index" // Refers to a resource offering help (more information, links to other sources information, etc.). RelTypeHelp RelType = "help" // Refers to a resource that can be used to edit the link's context. RelTypeEdit RelType = "edit" )
type Resource ¶
type Resource struct {
Links Links `json:"_links,omitempty"`
Embedded Embedded `json:"_embedded,omitempty"`
Props Props `json:"-"`
}
Resource is a flat HAL Resource Object. _links, _embedded, and all
func (Resource) MarshalJSON ¶
type ResponseWriter ¶
type ResponseWriter struct {
http.ResponseWriter
// contains filtered or unexported fields
}
func (*ResponseWriter) WriteHeader ¶
func (rw *ResponseWriter) WriteHeader(code int)
type RouteConfig ¶
type Scope ¶
type Scope []ScopeValue
type ScopeValue ¶
type ScopeValue string
const ( ScopeValueCandidate ScopeValue = "role:candidate" ScopeValueRecruiter ScopeValue = "role:recruiter" ScopeValueOnboarding ScopeValue = "role:onboarding" )
func ToScopeValue ¶
func ToScopeValue(str string) (ScopeValue, error)
type ServerConfig ¶
type StateTokenClaims ¶
type StoreConfig ¶
type StoreImpl ¶
func NewStore ¶
func NewStore(c StoreConfig) (*StoreImpl, error)
func (StoreImpl) CreateCandidate ¶
CreateCandidate creates a candidate
func (StoreImpl) CreateReaction ¶
CreateReaction records a reaction (from a candidate or recruiter) to a recommendation.
func (StoreImpl) CreateRecommendation ¶
CreateRecommendation inserts a new recommendation for a candidate and a position.
func (StoreImpl) CreateRecruiter ¶
CreateRecruiter creates a recruiter
func (StoreImpl) CreateRefreshToken ¶
CreateRefreshToken creates a new refresh token record.
func (StoreImpl) CreateUser ¶
CreateUser generates a unique username and inserts a new user record.
func (StoreImpl) GetCandidateByUserID ¶
GetCandidateByUserID fetches a candidate by their associated user ID.
func (StoreImpl) GetCandidateRecommendations ¶
func (StoreImpl) GetMatchesByCandidateID ¶
func (s StoreImpl) GetMatchesByCandidateID(candidateID ULID, page Page) (matches []Match, nextCursor ULID, err error)
GetMatchesByCandidateID returns paginated matches for a candidate.
func (StoreImpl) GetPositionRecommendations ¶
func (s StoreImpl) GetPositionRecommendations(candidateID ULID, page Page, excludeReacted bool) (positionRecommendations []PositionRecommendation, nextCursor ULID, err error)
GetPositionRecommendations returns paginated position recommendations for a candidate.
func (StoreImpl) GetReactionsByCandidateID ¶
func (s StoreImpl) GetReactionsByCandidateID(candidateID ULID, page Page) (reactions []Reaction, nextCursor ULID, err error)
GetReactionsByCandidateID returns paginated reactions made by a candidate.
func (StoreImpl) GetRecommendation ¶
func (s StoreImpl) GetRecommendation(id ULID) (*Recommendation, error)
func (StoreImpl) GetRecruiterByUserID ¶
GetRecruiterByUserID fetches a recruiter by their associated user ID.
func (StoreImpl) GetUserByProvider ¶
func (s StoreImpl) GetUserByProvider(provider Provider, providerUserID string) (ULID, map[Role]ULID, error)
GetUserByProvider retrieves an existing user and his role based on their provider details.
func (StoreImpl) GetUserRoles ¶
GetUserRoles fetches user roles by user's ID and provider.
type StoreInterface ¶
type StoreInterface interface {
CreateCandidate(Candidate) error
CreateReaction(Reaction) error
CreateRecommendation(positionID, candidateID ULID) (ULID, error)
CreateRecruiter(Recruiter) error
CreateRefreshToken(userID ULID, expiresAt time.Time) (jti ULID, err error)
CreateUser(User) (userID ULID, err error)
GetReactionsByCandidateID(ULID, Page) (reactions []Reaction, nextCursor ULID, err error)
GetMatchesByCandidateID(ULID, Page) (matches []Match, nextCursos ULID, err error)
GetPosition(ULID) (*Position, error)
GetUserByProvider(Provider, string) (ULID, map[Role]ULID, error)
GetRecommendation(ULID) (*Recommendation, error)
GetUserRoles(ULID, Provider) (map[Role]ULID, error)
GetPositionRecommendations(candidateID ULID, page Page, excludeReacted bool) (positionRecommendations []PositionRecommendation, nextCursor ULID, err error)
GetCandidateRecommendations(candidateID ULID, page Page, excludeReacted bool) (candidateRecommenations []CandidateRecommendation, nextCursor ULID, err error)
IsActiveSession(jti ULID) (bool, error)
}
type User ¶
type User struct {
ID ULID `json:"id,omitempty"`
Provider Provider `json:"provider,omitempty"`
ProviderUserID string `json:"provider_user_id,omitempty"`
Email string `json:"email,omitempty"`
FullName string `json:"full_name,omitempty"`
UserName string `json:"user_name"`
}
User represents a system user
type VaultConfig ¶
type VaultImpl ¶
type VaultImpl struct {
AccessTokenParser paseto.Parser
RefreshTokenParser paseto.Parser
StateTokenParser paseto.Parser
V4AsymmetricPublicKey paseto.V4AsymmetricPublicKey
V4AsymmetricSecretKey paseto.V4AsymmetricSecretKey
V4SymmetricKey paseto.V4SymmetricKey
GoogleOIDCConfig OIDCConfig
AppleOIDCConfig OIDCConfig
RefreshTokenExpiration time.Duration
AccessTokenExpiration time.Duration
}
func (VaultImpl) CreateAccessToken ¶
func (VaultImpl) CreateAuthCodeURL ¶
func (VaultImpl) CreateRefreshToken ¶
func (VaultImpl) CreateStateToken ¶
func (VaultImpl) CreateTokenPair ¶
func (VaultImpl) ExchangeAppleCodeForIDToken ¶
func (VaultImpl) ExchangeGoogleCodeForIDToken ¶
func (VaultImpl) ParseAccessToken ¶
func (v VaultImpl) ParseAccessToken(tokenString string) (*AccessTokenClaims, error)
func (VaultImpl) ParseRefreshToken ¶
func (v VaultImpl) ParseRefreshToken(tokenString string) (*RefreshTokenClaims, error)
func (VaultImpl) ParseStateToken ¶
func (v VaultImpl) ParseStateToken(raw string) (*StateTokenClaims, error)
func (VaultImpl) VerifyAndParseAppleIDToken ¶
type VaultInterface ¶
type VaultInterface interface {
CreateAccessToken(userID ULID, provider Provider, roles map[Role]ULID) (*AccessToken, error)
CreateAuthCodeURL(state string, verifier string, provider Provider) (string, error)
CreateRefreshToken(userID ULID, provider Provider, jti ULID) (*RefreshToken, error)
CreateTokenPair(userID ULID, provider Provider, jti ULID, roles map[Role]ULID) (*TokenPair, error)
CreateStateToken(provider Provider) (string, error)
ExchangeAppleCodeForIDToken(ctx context.Context, code string, verifier *http.Cookie) (string, error)
ExchangeGoogleCodeForIDToken(ctx context.Context, code string, verifier *http.Cookie) (string, error)
ParseAccessToken(token string) (*AccessTokenClaims, error)
ParseRefreshToken(token string) (*RefreshTokenClaims, error)
ParseStateToken(token string) (*StateTokenClaims, error)
VerifyAndParseAppleIDToken(ctx context.Context, rawIDToken string, userJSON string) (*User, error)
VerifyAndParseGoogleIDToken(ctx context.Context, rawIDToken string) (*User, error)
}