user

package
v1.11.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 10, 2023 License: BSD-2-Clause Imports: 45 Imported by: 0

Documentation

Index

Constants

View Source
const (

	//api logging prefix
	USER_API_PREFIX = "api/user "

	TP_SERVER_NAME    = "x-tidepool-server-name"
	TP_SERVER_SECRET  = "x-tidepool-server-secret"
	TP_SESSION_TOKEN  = "x-tidepool-session-token"
	EXT_SESSION_TOKEN = "x-external-session-token"
	// TP_TRACE_SESSION Session trace: uuid v4
	TP_TRACE_SESSION      = "x-tidepool-trace-session"
	HEADER_REQUEST_SOURCE = "x-backloops-source"

	STATUS_NO_USR_DETAILS                 = "No user details were given"
	STATUS_INVALID_USER_DETAILS           = "Invalid user details were given"
	STATUS_USER_NOT_FOUND                 = "User not found"
	STATUS_ERR_FINDING_USR                = "Error finding user"
	STATUS_ERR_CREATING_USR               = "Error creating the user"
	STATUS_ERR_UPDATING_USR               = "Error updating user"
	STATUS_USR_ALREADY_EXISTS             = "User already exists"
	STATUS_ID_ALREADY_USED                = "OIDC Id is already assigned to another user"
	STATUS_ERR_GENERATING_TOKEN           = "Error generating the token"
	STATUS_ERR_UPDATING_TOKEN             = "Error updating token"
	STATUS_MISSING_USR_DETAILS            = "Not all required details were given"
	STATUS_ERROR_UPDATING_PW              = "Error updating password"
	STATUS_MISSING_ID_PW                  = "Missing id and/or password"
	STATUS_NO_MATCH                       = "No user matched the given details"
	STATUS_NOT_VERIFIED                   = "The user hasn't verified this account yet"
	STATUS_NO_TOKEN_MATCH                 = "No token matched the given details"
	STATUS_PW_WRONG                       = "Wrong password"
	STATUS_ERR_SENDING_EMAIL              = "Error sending email"
	STATUS_NO_TOKEN                       = "No x-tidepool-session-token was found"
	STATUS_SERVER_TOKEN_REQUIRED          = "A server token is required"
	STATUS_AUTH_HEADER_REQUIRED           = "Authorization header is required"
	STATUS_AUTH_HEADER_INVLAID            = "Authorization header is invalid"
	STATUS_GETSTATUS_ERR                  = "Error checking service status"
	STATUS_UNAUTHORIZED                   = "Not authorized for requested operation"
	STATUS_NO_QUERY                       = "A query must be specified"
	STATUS_PARAMETER_UNKNOWN              = "Unknown query parameter"
	STATUS_ONE_QUERY_PARAM                = "Only one query parameter is allowed"
	STATUS_INVALID_ROLE                   = "The role specified is invalid"
	STATUS_INVALID_EMAIL_VERIF_BOOL_PARAM = "The emailVerified query parameter must be a boolean"
	STATUS_OK                             = "OK"
	STATUS_NO_EXPECTED_PWD                = "No expected password is found"
)
View Source
const (
	USERS_COLLECTION  = "users"
	TOKENS_COLLECTION = "tokens"
	DIRTY_COLLECTION  = "dirty"
)

Variables

View Source
var (
	ErrUserDetailsMissing         = errors.New("user details are missing")
	ErrUserUsernameMissing        = errors.New("username is missing")
	ErrUserUsernameInvalid        = errors.New("username is invalid")
	ErrUserEmailsMissing          = errors.New("emails are missing")
	ErrUserEmailsInvalid          = errors.New("emails are invalid")
	ErrUserPasswordMissing        = errors.New("password is missing")
	ErrUserPasswordInvalid        = errors.New("password is invalid")
	ErrUserCurrentPasswordInvalid = errors.New("current password is invalid")
	ErrUserNewPasswordInvalid     = errors.New("new password is invalid")
	ErrUserRolesInvalid           = errors.New("roles are invalid")
	ErrUserRolesMissing           = errors.New("role is missing")
	ErrUserTermsAcceptedInvalid   = errors.New("terms accepted is invalid")
	ErrUserEmailVerifiedInvalid   = errors.New("email verified is invalid")
)

Functions

func CreateSessionTokenAndSave

func CreateSessionTokenAndSave(ctx context.Context, data *token.TokenData, config token.TokenConfig, store Storage) (*token.SessionToken, error)

func ExtractArray

func ExtractArray(data map[string]interface{}, key string) ([]interface{}, bool)

func ExtractBool

func ExtractBool(data map[string]interface{}, key string) (*bool, bool)

func ExtractSanitizedString added in v1.9.0

func ExtractSanitizedString(data map[string]interface{}, key string) (*string, bool)

func ExtractString

func ExtractString(data map[string]interface{}, key string) (*string, bool)

func ExtractStringArray

func ExtractStringArray(data map[string]interface{}, key string) ([]string, bool)

func ExtractStringMap

func ExtractStringMap(data map[string]interface{}, key string) (map[string]interface{}, bool)

func GeneratePasswordHash

func GeneratePasswordHash(id, pw, salt string) (string, error)

func IsValidBoolean added in v1.8.5

func IsValidBoolean(val string) bool

func IsValidDate

func IsValidDate(date string) bool

func IsValidEmail

func IsValidEmail(email string) bool

func IsValidPassword

func IsValidPassword(password string) bool

func IsValidRole

func IsValidRole(role string) bool

func IsValidTimestamp

func IsValidTimestamp(timestamp string) bool

Types

type AnonIdHashPair

type AnonIdHashPair struct {
	Name string `json:"name"`
	Id   string `json:"id"`
	Hash string `json:"hash"`
}

func NewAnonIdHashPair

func NewAnonIdHashPair(baseStrings []string, params map[string][]string) *AnonIdHashPair

type Api

type Api struct {
	Store     Storage
	ApiConfig *ApiConfig
	// contains filtered or unexported fields
}

Api struct used by shoreline server components

func New added in v1.8.2

func New(cfg *ApiConfig, logger *log.Logger, store Storage, auditLogger *log.Logger, auth0Client *auth0.Auth0Client) *Api

New create a new shoreline API config

func (*Api) AnonymousIdHashPair

func (a *Api) AnonymousIdHashPair(res http.ResponseWriter, req *http.Request)

@Summary AnonymousIdHashPair ? @Description AnonymousIdHashPair ? @ID shoreline-user-api-anonymousidhashpair @Accept json @Produce json @Success 200 {object} user.AnonIdHashPair "AnonymousIdHashPair?" @Router /private [get]

func (*Api) CreateUser

func (a *Api) CreateUser(res http.ResponseWriter, req *http.Request)

@Summary Create user @Description Create user @ID shoreline-user-api-createuser @Accept json @Produce json @Param user body user.NewUserDetails true "user details" @Success 201 {object} user.User @Header 201 {string} x-tidepool-session-token "authentication token" @Failure 500 {object} status.Status "message returned:\"Error creating the user\" or \"Error generating the token\" " @Failure 400 {object} status.Status "message returned:\"Invalid user details were given\" " @Router /user [post]

func (*Api) DelegatedLoginCallback added in v1.9.0

func (a *Api) DelegatedLoginCallback(res http.ResponseWriter, req *http.Request)

OIDC callback method

func (*Api) DeleteUser

func (a *Api) DeleteUser(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Delete user @Description Delete user @ID shoreline-user-api-deleteuser @Accept json @Produce json @Param userid path int true "user id for server request, from token for personal request" optional @Param password body string false "password mandatory for personal request" @Security TidepoolAuth @Success 202 "User deleted" @Failure 500 {string} string "" @Failure 403 {object} status.Status "message returned:\"Missing id and/or password\" " @Failure 401 {string} string "" @Router /user/{userid} [delete]

func (*Api) Get3rdPartyToken added in v1.8.2

func (a *Api) Get3rdPartyToken(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Generate a 3rd party JWT @Description Generate a token to authenticate the user to a 3rd party service @ID shoreline-user-api-getToken @Param service path string true "3rd party service name" @Security TidepoolAuth @Success 200 {object} status.Status @Header 200 {string} x-external-session-token "3rd party token" @Failure 500 {object} status.Status "message returned:\"Error generating the token" " @Failure 401 {object} status.Status "message returned:\"Not authorized for requested operation\" " @Failure 400 {object} status.Status "message returned:\"Unknown query parameter\" or \"Error generating the token\" " @Router /ext-token/{service} [post]

func (*Api) GetStatus

func (a *Api) GetStatus(res http.ResponseWriter, req *http.Request)

@Summary Get the api status @Description Get the api status @ID shoreline-user-api-getstatus @Accept json @Produce json @Success 200 "Status ok" @Failure 500 {string} string "error description" @Router /status [get]

func (*Api) GetUserInfo

func (a *Api) GetUserInfo(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Get user information @Description Get user information @ID shoreline-user-api-getuserinfo @Accept json @Produce json @Param userid path int true "user id" optional @Security TidepoolAuth @Success 200 {object} user.User @Failure 500 {object} status.Status "message returned:\"Error finding user\" " @Failure 404 {object} status.Status "message returned:\"User not found\" " @Failure 401 {object} status.Status "message returned:\"Not authorized for requested operation\" " @Router /user/{userid} [get]

func (*Api) GetUsers

func (a *Api) GetUsers(res http.ResponseWriter, req *http.Request)

@Summary Get users @Description Get users @ID shoreline-user-api-getusers @Accept json @Produce json @Param role query string false "Role. Exactly one query parameter is required in role, id, emailVerified" Enums(clinic) @Param id query string false "List of UserId separated by ,. Exactly one query parameter is required in role, id, emailVerified" @Param emailVerified query boolean false "Filter users on emailVerified. Exactly one query parameter is required in role, id, emailVerified" @Security TidepoolAuth @Success 200 {array} user.User @Failure 500 {object} status.Status "message returned:\"Error finding user\" " @Failure 400 {object} status.Status "message returned:\"The role specified is invalid\" or \"A query must be specified\" or \"Only one query parameter is allowed\" or \"Unknown query parameter\"" @Failure 401 {object} status.Status "message returned:\"Not authorized for requested operation\" " @Router /users [get]

func (*Api) Login

func (a *Api) Login(res http.ResponseWriter, req *http.Request)

@Summary Login user @Description Login user @ID shoreline-user-api-login @Accept json @Produce json @Param tokenduration header number false "token duration" @Security BasicAuth @Success 200 {object} user.User @Header 200 {string} x-tidepool-session-token "au" @Failure 500 {object} status.Status "message returned: \"Error updating token\"" @Failure 403 {object} status.Status "message returned: \"The user hasn't verified this account yet\"" @Failure 401 {object} status.Status "message returned: \"No user matched the given details\"" @Failure 400 {object} status.Status "message returned: \"Missing id and/or password\"" @Router /login [post]

func (*Api) Logout

func (a *Api) Logout(res http.ResponseWriter, req *http.Request)

@Summary Logout @Description Logout @ID shoreline-user-api-logout @Accept json @Produce json @Security TidepoolAuth @Success 200 {string} string "" @Router /logout [post]

func (*Api) LongtermLogin

func (a *Api) LongtermLogin(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Longterm login @Description Longterm login @ID shoreline-user-api-longtermlogin @Accept json @Produce json @Param longtermkey path string true "long term key" @Security BasicAuth @Success 200 {object} user.User @Header 200 {string} x-tidepool-session-token "authentication token" @Failure 500 {object} status.Status "message returned:\"Error finding user\" or \"Error updating token\" " @Failure 403 {object} status.Status "message returned:\"The user hasn't verified this account yet\" " @Failure 401 {object} status.Status "message returned:\"No user matched the given details\" " @Failure 400 {object} status.Status "message returned:\"Missing id and/or password\" " @Router /login/{longtermkey} [post] Set the longeterm duration and then process as per Login note: see Login for return codes

func (*Api) RefreshSession

func (a *Api) RefreshSession(res http.ResponseWriter, req *http.Request)

@Summary Refresh session @Description Refresh session @ID shoreline-user-api-refreshsession @Accept json @Produce json @Param x-tidepool-server-name header string true "server name" @Param x-tidepool-server-secret header string true "server secret" @Security TidepoolAuth @Success 200 {object} token.TokenData "Token details" @Header 200 {string} x-tidepool-session-token "authentication token" @Failure 500 {object} status.Status "message returned:\"Error generating the token\" " @Failure 401 {string} string "" @Router /login [get]

func (*Api) ServerCheckToken

func (a *Api) ServerCheckToken(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Check server token @Description Check server token @ID shoreline-user-api-serverchecktoken @Accept json @Produce json @Param token path string true "server token to check" @Security TidepoolAuth @Success 200 {object} token.TokenData "Token details" @Failure 401 {object} status.Status "message returned:\"No x-tidepool-session-token was found\" " @Router /token/{token} [get]

func (*Api) ServerLogin

func (a *Api) ServerLogin(res http.ResponseWriter, req *http.Request)

@Summary Login server @Description Login server @ID shoreline-user-api-serverlogin @Accept json @Produce json @Param x-tidepool-server-name header string true "server name" @Param x-tidepool-server-secret header string true "server secret" @Success 200 "Authentication successfull" @Header 200 {string} x-tidepool-session-token "authentication token" @Failure 500 {object} status.Status "message returned:\"Error generating the token\" or \"No expected password is found\"" @Failure 401 {object} status.Status "message returned:\"Wrong password\" " @Failure 400 {object} status.Status "message returned:\"Missing id and/or password\" " @Router /serverlogin [post]

func (*Api) SetHandlers

func (a *Api) SetHandlers(prefix string, rtr *mux.Router)

SetHandlers init the HTTP routes handlers

func (*Api) UpdateUser

func (a *Api) UpdateUser(res http.ResponseWriter, req *http.Request, vars map[string]string)

@Summary Update user @Description Update user @ID shoreline-user-api-updateuser @Accept json @Produce json @Param userid path int true "user id" @Param user body user.UpdateUserDetails true "user update details" @Security TidepoolAuth @Success 200 {object} user.UpdateUserDetails @Failure 304 {object} status.Status "message returned:\"Error updating user\" or \"Error finding user\" " @Failure 500 {object} status.Status "message returned:\"Invalid user details were given\"" @Failure 409 {object} status.Status "message returned:\"User already exists\" " @Failure 401 {object} status.Status "message returned:\"Not authorized for requested operation\" " @Failure 400 {object} status.Status "message returned:\"Invalid user details were given\" " @Router /user/{userid} [put]

func (*Api) UpdateUserAfterFailedLogin added in v1.8.2

func (a *Api) UpdateUserAfterFailedLogin(ctx context.Context, u *User) error

UpdateUserAfterFailedLogin update the user failed login infos in database

func (*Api) UpdateUserAfterSuccessfulLogin added in v1.8.2

func (a *Api) UpdateUserAfterSuccessfulLogin(ctx context.Context, u *User) error

UpdateUserAfterSuccessfulLogin update the user after a successful login

func (*Api) UpdateUserWithOauth added in v1.9.0

func (a *Api) UpdateUserWithOauth(res http.ResponseWriter, req *http.Request)

@Summary Update an HCP user with an external OAuth ID @Description Merge an external oauth uid with a yourloops user @ID shoreline-user-api-updateOauth @Accept json @Produce json @Security TidepoolAuth @Security OIDC cookie @Success 202 "User updated" @Failure 500 {string} string "" @Failure 401 {string} string "" @Router /oauth/merge [post]

type ApiConfig

type ApiConfig struct {
	//base url which (publicly) exposes shoreline service
	PublicApiURl string
	//base url of front-end, used for oidc login redirect
	FrontUrl string
	//used for services
	ServerSecrets     map[string]string
	LongTermKey       string `json:"longTermKey"`
	LongTermsDuration int64  `json:"longTermDuration"`
	// UserTokenDuration is the token duration for user token
	UserTokenDurationSecs int64
	// ServerTokenDuration is the token duration for server tokens
	ServerTokenDurationSecs int64
	//used for pw
	Salt string `json:"salt"`
	//used for token
	Secret       string `json:"apiSecret"`
	TokenSecrets map[string]string
	//used to delegate auth to OAuth/OIDC server
	OAuthAppConfig OAuthConfig
	// Maximum number of consecutive failed login before a delay is set
	MaxFailedLogin int `json:"maxFailedLogin"`
	// Delay in minutes the user must wait 10min before attempting a new login if the number of
	// consecutive failed login is more than MaxFailedLogin
	DelayBeforeNextLoginAttempt int64 `json:"delayBeforeNextLoginAttempt"`
	// Maximum number of concurrent login
	MaxConcurrentLogin int `json:"maxConcurrentLogin"`
	// Block users to do multiple parallel logins (for load tests we desactivate this)
	BlockParallelLogin bool `json:"blockParallelLogin"`
	//allows for the skipping of verification for testing
	VerificationSecret string `json:"verificationSecret"`
}

ApiConfig for shoreline

func NewConfigFromEnv added in v1.8.2

func NewConfigFromEnv(log *log.Logger) *ApiConfig

NewConfigFromEnv create the configuration from environnement variables

type Client added in v1.8.2

type Client struct {
	*goComMgo.StoreClient
}

Client struct

func NewStore added in v1.8.2

func NewStore(config *goComMgo.Config, logger *log.Logger) (*Client, error)

NewStore creates a new Client

func (*Client) AddToken added in v1.8.2

func (c *Client) AddToken(ctx context.Context, st *token.SessionToken) error

func (*Client) ExistDirtyUser added in v1.9.1

func (c *Client) ExistDirtyUser(ctx context.Context, username string) (res bool)

func (*Client) FindTokenByID added in v1.8.2

func (c *Client) FindTokenByID(ctx context.Context, id string) (*token.SessionToken, error)

func (*Client) FindUser added in v1.8.2

func (c *Client) FindUser(ctx context.Context, user *User) (result *User, err error)

func (*Client) FindUsers added in v1.8.2

func (c *Client) FindUsers(ctx context.Context, user *User) (results []*User, err error)

func (*Client) FindUsersByEmailVerified added in v1.8.5

func (c *Client) FindUsersByEmailVerified(ctx context.Context, emailVerified bool) ([]*User, error)

func (*Client) FindUsersByRole added in v1.8.2

func (c *Client) FindUsersByRole(ctx context.Context, role string) (results []*User, err error)

func (*Client) FindUsersWithIds added in v1.8.2

func (c *Client) FindUsersWithIds(ctx context.Context, ids []string) (results []*User, err error)

func (*Client) RemoveTokenByID added in v1.8.2

func (c *Client) RemoveTokenByID(ctx context.Context, id string) (err error)

func (*Client) RemoveUser added in v1.8.2

func (c *Client) RemoveUser(ctx context.Context, user *User) (err error)

func (*Client) UpsertDirty added in v1.9.1

func (c *Client) UpsertDirty(ctx context.Context, username string) error

func (*Client) UpsertUser added in v1.8.2

func (c *Client) UpsertUser(ctx context.Context, user *User) error

type ExistDirtyUserReponse added in v1.9.1

type ExistDirtyUserReponse struct {
	Exist bool
}

type FailedLoginInfos added in v1.8.2

type FailedLoginInfos struct {
	// Count is the current number of failed login since previous success (reset to 0 after each successful login)
	Count int `json:"-" bson:"count"`
	// Total number of failed login attempt (this value is never reset to 0)
	Total int `json:"-" bson:"total"`
	// Next time we may consider a valid login attempt on this account
	NextLoginAttemptTime string `json:"-" bson:"nextLoginAttemptTime,omitempty"`
}

FailedLoginInfos monitor the failed login of an user account.

type FindTokenByIDResponse

type FindTokenByIDResponse struct {
	SessionToken *token.SessionToken
	Error        error
}

type FindUserResponse

type FindUserResponse struct {
	User  *User
	Error error
}

type FindUsersByEmailVerifiedResponse added in v1.8.5

type FindUsersByEmailVerifiedResponse struct {
	Users []*User
	Error error
}

type FindUsersByRoleResponse

type FindUsersByRoleResponse struct {
	Users []*User
	Error error
}

type FindUsersResponse

type FindUsersResponse struct {
	Users []*User
	Error error
}

type FindUsersWithIdsResponse added in v1.8.2

type FindUsersWithIdsResponse struct {
	Users []*User
	Error error
}

type IdHashPair

type IdHashPair struct {
	Id   string `json:"id"`
	Hash string `json:"hash"`
}

func NewIdHashPair

func NewIdHashPair(baseStrings []string, params map[string][]string) *IdHashPair

type LoginLimiter added in v1.8.2

type LoginLimiter struct {
	// contains filtered or unexported fields
}

LoginLimiter var needed to limit the max login attempt on an account

type MockStoreClient

type MockStoreClient struct {
	// contains filtered or unexported fields
}

func NewMockStoreClient

func NewMockStoreClient(salt string, returnDifferent, doBad bool) *MockStoreClient

func (MockStoreClient) AddToken

func (d MockStoreClient) AddToken(ctx context.Context, token *token.SessionToken) error

func (*MockStoreClient) Close

func (d *MockStoreClient) Close() error

func (*MockStoreClient) Collection added in v1.8.2

func (d *MockStoreClient) Collection(collectionName string, databaseName ...string) *mongo.Collection

func (MockStoreClient) ExistDirtyUser added in v1.9.1

func (d MockStoreClient) ExistDirtyUser(ctx context.Context, username string) (res bool)

func (MockStoreClient) FindTokenByID

func (d MockStoreClient) FindTokenByID(ctx context.Context, id string) (*token.SessionToken, error)

func (MockStoreClient) FindUser

func (d MockStoreClient) FindUser(ctx context.Context, user *User) (found *User, err error)

func (MockStoreClient) FindUsers

func (d MockStoreClient) FindUsers(ctx context.Context, user *User) (found []*User, err error)

func (MockStoreClient) FindUsersByEmailVerified added in v1.8.5

func (d MockStoreClient) FindUsersByEmailVerified(ctx context.Context, auth bool) (found []*User, err error)

func (MockStoreClient) FindUsersByRole

func (d MockStoreClient) FindUsersByRole(ctx context.Context, role string) (found []*User, err error)

func (MockStoreClient) FindUsersWithIds added in v1.8.2

func (d MockStoreClient) FindUsersWithIds(ctx context.Context, ids []string) (found []*User, err error)

func (MockStoreClient) Ping

func (d MockStoreClient) Ping() error

func (*MockStoreClient) PingOK added in v1.8.2

func (d *MockStoreClient) PingOK() bool

func (MockStoreClient) RemoveTokenByID

func (d MockStoreClient) RemoveTokenByID(ctx context.Context, id string) error

func (MockStoreClient) RemoveUser

func (d MockStoreClient) RemoveUser(ctx context.Context, user *User) error

func (*MockStoreClient) Start added in v1.8.2

func (d *MockStoreClient) Start()

func (MockStoreClient) UpsertUser

func (d MockStoreClient) UpsertUser(ctx context.Context, user *User) error

func (*MockStoreClient) WaitUntilStarted added in v1.8.2

func (d *MockStoreClient) WaitUntilStarted()

type NewCustodialUserDetails

type NewCustodialUserDetails struct {
	Username *string
	Emails   []string
}

func ParseNewCustodialUserDetails

func ParseNewCustodialUserDetails(reader io.Reader) (*NewCustodialUserDetails, error)

func (*NewCustodialUserDetails) ExtractFromJSON

func (details *NewCustodialUserDetails) ExtractFromJSON(reader io.Reader) error

func (*NewCustodialUserDetails) Validate

func (details *NewCustodialUserDetails) Validate() error

type NewUserDetails

type NewUserDetails struct {
	Username *string
	Emails   []string
	Password *string
	Roles    []string
}

* Incoming user details used to create or update a `User`

func ParseNewUserDetails

func ParseNewUserDetails(reader io.Reader) (*NewUserDetails, error)

func (*NewUserDetails) ExtractFromJSON

func (details *NewUserDetails) ExtractFromJSON(reader io.Reader) error

func (*NewUserDetails) Validate

func (details *NewUserDetails) Validate(requestSource string) error

type OAuthConfig added in v1.9.0

type OAuthConfig struct {
	DiscoveryUrl string `json:"discoveryUrl"`
	IssuerUri    string `json:"issuer"`
	Secret       string `json:"secret"`
	ClientId     string `json:"clientid"`
	Key          string `json:"key"`
}

type OidcTokens added in v1.9.0

type OidcTokens struct {
	AuthToken    string `json:"auth"`
	RefreshToken string `json:"refresh"`
}

Simple structure to store and exchange OIDC tokens with our frontend

func (*OidcTokens) Decode added in v1.9.0

func (t *OidcTokens) Decode(val string) error

Decode JSON representation of our OIDC tokens into OidcTokens struct

func (*OidcTokens) Encode added in v1.9.0

func (t *OidcTokens) Encode() (string, error)

Encode tokens to JSON (used to send on HTTP responses)

type ResponsableMockStoreClient

type ResponsableMockStoreClient struct {
	PingResponses                     []error
	UpsertUserResponses               []error
	FindUsersResponses                []FindUsersResponse
	FindUsersByRoleResponses          []FindUsersByRoleResponse
	FindUsersByEmailVerifiedResponses []FindUsersByEmailVerifiedResponse
	FindUsersWithIdsResponses         []FindUsersWithIdsResponse
	FindUserResponses                 []FindUserResponse
	ExistDirtyUserReponses            []ExistDirtyUserReponse
	RemoveUserResponses               []error
	AddTokenResponses                 []error
	FindTokenByIDResponses            []FindTokenByIDResponse
	RemoveTokenByIDResponses          []error
}

func NewResponsableMockStoreClient

func NewResponsableMockStoreClient() *ResponsableMockStoreClient

func (*ResponsableMockStoreClient) AddToken

func (r *ResponsableMockStoreClient) AddToken(ctx context.Context, token *token.SessionToken) (err error)

func (*ResponsableMockStoreClient) Close

func (r *ResponsableMockStoreClient) Close() error

func (*ResponsableMockStoreClient) Collection added in v1.8.2

func (r *ResponsableMockStoreClient) Collection(collectionName string, databaseName ...string) *mongo.Collection

func (*ResponsableMockStoreClient) ExistDirtyUser added in v1.9.1

func (r *ResponsableMockStoreClient) ExistDirtyUser(ctx context.Context, username string) bool

func (*ResponsableMockStoreClient) FindTokenByID

func (*ResponsableMockStoreClient) FindUser

func (r *ResponsableMockStoreClient) FindUser(ctx context.Context, user *User) (found *User, err error)

func (*ResponsableMockStoreClient) FindUsers

func (r *ResponsableMockStoreClient) FindUsers(ctx context.Context, user *User) (found []*User, err error)

func (*ResponsableMockStoreClient) FindUsersByEmailVerified added in v1.8.5

func (r *ResponsableMockStoreClient) FindUsersByEmailVerified(ctx context.Context, emailVerif bool) (found []*User, err error)

func (*ResponsableMockStoreClient) FindUsersByRole

func (r *ResponsableMockStoreClient) FindUsersByRole(ctx context.Context, role string) (found []*User, err error)

func (*ResponsableMockStoreClient) FindUsersWithIds added in v1.8.2

func (r *ResponsableMockStoreClient) FindUsersWithIds(ctx context.Context, ids []string) (found []*User, err error)

func (*ResponsableMockStoreClient) HasResponses

func (r *ResponsableMockStoreClient) HasResponses() bool

func (*ResponsableMockStoreClient) Ping

func (r *ResponsableMockStoreClient) Ping() (err error)

func (*ResponsableMockStoreClient) PingOK added in v1.8.2

func (r *ResponsableMockStoreClient) PingOK() bool

func (*ResponsableMockStoreClient) RemoveTokenByID

func (r *ResponsableMockStoreClient) RemoveTokenByID(ctx context.Context, id string) (err error)

func (*ResponsableMockStoreClient) RemoveUser

func (r *ResponsableMockStoreClient) RemoveUser(ctx context.Context, user *User) (err error)

func (*ResponsableMockStoreClient) Reset

func (r *ResponsableMockStoreClient) Reset()

func (*ResponsableMockStoreClient) Start added in v1.8.2

func (r *ResponsableMockStoreClient) Start()

func (*ResponsableMockStoreClient) UpsertUser

func (r *ResponsableMockStoreClient) UpsertUser(ctx context.Context, user *User) (err error)

func (*ResponsableMockStoreClient) WaitUntilStarted added in v1.8.2

func (r *ResponsableMockStoreClient) WaitUntilStarted()

type Secret added in v1.8.2

type Secret struct {
	Secret string `json:"secret"`
	Pass   string `json:"pass"`
}

type Storage

type Storage interface {
	goComMgo.Storage
	UpsertUser(ctx context.Context, user *User) error
	FindUser(ctx context.Context, user *User) (*User, error)
	ExistDirtyUser(ctx context.Context, username string) bool
	FindUsers(ctx context.Context, user *User) ([]*User, error)
	FindUsersByRole(ctx context.Context, role string) ([]*User, error)
	FindUsersByEmailVerified(ctx context.Context, auth bool) ([]*User, error)
	FindUsersWithIds(ctx context.Context, role []string) ([]*User, error)
	RemoveUser(ctx context.Context, user *User) error
	AddToken(ctx context.Context, token *token.SessionToken) error
	FindTokenByID(ctx context.Context, id string) (*token.SessionToken, error)
	RemoveTokenByID(ctx context.Context, id string) error
}

type UpdateUserDetails

type UpdateUserDetails struct {
	Username        *string
	Emails          []string
	CurrentPassword *string
	Password        *string
	Roles           []string
	TermsAccepted   *string
	EmailVerified   *bool
	// contains filtered or unexported fields
}

func ParseUpdateUserDetails

func ParseUpdateUserDetails(reader io.Reader) (*UpdateUserDetails, error)

func (*UpdateUserDetails) ExtractFromJSON

func (details *UpdateUserDetails) ExtractFromJSON(reader io.Reader) error

func (*UpdateUserDetails) Validate

func (details *UpdateUserDetails) Validate() error

type User

type User struct {
	Id             string                 `json:"userid,omitempty" bson:"userid,omitempty"` // map userid to id
	Username       string                 `json:"username,omitempty" bson:"username,omitempty"`
	FrProId        string                 `json:"frProId,omitempty" bson:"frProId,omitempty"`
	Emails         []string               `json:"emails,omitempty" bson:"emails,omitempty"`
	Roles          []string               `json:"roles,omitempty" bson:"roles,omitempty"`
	TermsAccepted  string                 `json:"termsAccepted,omitempty" bson:"termsAccepted,omitempty"`
	EmailVerified  bool                   `json:"emailVerified" bson:"authenticated"` //tag is name `authenticated` for historical reasons
	PwHash         string                 `json:"-" bson:"pwhash,omitempty"`
	Hash           string                 `json:"-" bson:"userhash,omitempty"`
	Private        map[string]*IdHashPair `json:"-" bson:"private"`
	FailedLogin    *FailedLoginInfos      `json:"-" bson:"failedLogin,omitempty"`
	CreatedTime    string                 `json:"createdTime,omitempty" bson:"createdTime,omitempty"`
	CreatedUserID  string                 `json:"createdUserId,omitempty" bson:"createdUserId,omitempty"`
	ModifiedTime   string                 `json:"modifiedTime,omitempty" bson:"modifiedTime,omitempty"`
	ModifiedUserID string                 `json:"modifiedUserId,omitempty" bson:"modifiedUserId,omitempty"`
	DeletedTime    string                 `json:"deletedTime,omitempty" bson:"deletedTime,omitempty"`
	DeletedUserID  string                 `json:"deletedUserId,omitempty" bson:"deletedUserId,omitempty"`
	IdVerified     bool                   `json:"idVerified,omitempty"`
}

func NewCustodialUser

func NewCustodialUser(details *NewCustodialUserDetails, salt string) (user *User, err error)

func NewUser

func NewUser(details *NewUserDetails, salt string, requestSource string) (user *User, err error)

func (*User) CanPerformALogin added in v1.8.2

func (u *User) CanPerformALogin(maxFailedLogin int) bool

CanPerformALogin check if the user can do a login

func (*User) DeepClone

func (u *User) DeepClone() *User

func (*User) Email

func (u *User) Email() string

func (*User) HasRole

func (u *User) HasRole(role string) bool

func (*User) HashPassword

func (u *User) HashPassword(pw, salt string) error

func (*User) IsClinic

func (u *User) IsClinic() bool

IsClinic returns true for hcp, caregiver or clinic user

Deprecated use HasRole() instead

func (*User) IsDeleted

func (u *User) IsDeleted() bool

func (*User) IsEmailVerified

func (u *User) IsEmailVerified(secret string) bool

func (*User) PasswordsMatch

func (u *User) PasswordsMatch(pw, salt string) bool

Directories

Path Synopsis

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL