Documentation
¶
Overview ¶
* Copyright Metaplay. Licensed under the Apache-2.0 license.
* Copyright Metaplay. Licensed under the Apache-2.0 license.
* Copyright Metaplay. Licensed under the Apache-2.0 license.
* Copyright Metaplay. Licensed under the Apache-2.0 license.
* Copyright Metaplay. Licensed under the Apache-2.0 license.
* Copyright Metaplay. Licensed under the Apache-2.0 license.
Index ¶
- func DeleteSessionState(sessionID string) error
- func LoginWithBrowser(ctx context.Context, authProvider *AuthProviderConfig) error
- func MachineLogin(authProvider *AuthProviderConfig, clientId, clientSecret string) error
- func SaveSessionState(sessionID string, userType UserType, tokenSet *TokenSet) error
- type AuthProviderConfig
- type MetaplayIDToken
- type PersistedConfig
- type PersistedSessionState
- type SessionState
- type TokenSet
- type UserInfoResponse
- type UserType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func DeleteSessionState ¶
DeleteSessionState removes the current session state (i.e., signs out the user).
func LoginWithBrowser ¶
func LoginWithBrowser(ctx context.Context, authProvider *AuthProviderConfig) error
func MachineLogin ¶
func MachineLogin(authProvider *AuthProviderConfig, clientId, clientSecret string) error
Types ¶
type AuthProviderConfig ¶
type AuthProviderConfig struct { Name string `yaml:"name"` // Name of the provider (used as sessionID as well). ClientID string `yaml:"clientId"` // OAuth2 client ID. AuthEndpoint string `yaml:"authEndpoint"` // Eg, "https://portal.metaplay.dev/oauth2/auth". TokenEndpoint string `yaml:"tokenEndpoint"` // Eg, "https://portal.metaplay.dev/oauth2/token". UserInfoEndpoint string `yaml:"userInfoEndpoint"` // Eg, "https://portal.metaplay.dev/api/external/userinfo" Scopes string `yaml:"scopes"` // Eg, "openid profile email offline_access" Audience string `yaml:"audience"` // Eg, "managed-gameservers" }
OAuth2 client configuration.
func NewMetaplayAuthProvider ¶
func NewMetaplayAuthProvider() *AuthProviderConfig
Create a default AuthProvider that uses Metaplay Auth.
func (*AuthProviderConfig) GetSessionID ¶
func (provider *AuthProviderConfig) GetSessionID() string
type MetaplayIDToken ¶
type MetaplayIDToken struct { *oidc.IDToken // Include all standard claims MetaplayEmail string `json:"https://schemas.metaplay.io/email"` // Email of the Metaplay portal user. MetaplayRoles []string `json:"https://schemas.metaplay.io/roles"` // Roles in Metaplay environments. }
func ResolveMetaplayIDToken ¶
func ResolveMetaplayIDToken(ctx context.Context, authProvider *AuthProviderConfig, idTokenStr string) (MetaplayIDToken, error)
type PersistedConfig ¶
type PersistedConfig struct {
Sessions map[string]PersistedSessionState `json:"sessions"` // Persisted sessions, use sessionID as key.
}
Represents the config.json persisted on disk.
type PersistedSessionState ¶
type PersistedSessionState struct { UserType UserType `json:"userType"` // Type of the user (human or machine) EncodedTokenSet string `json:"tokenSet"` // Encrypted tokenSet }
Persisted session state (with encrypted tokenSet).
type SessionState ¶
type SessionState struct { UserType UserType // Type of user in portal. TokenSet *TokenSet // TokenSet for the user. }
In-memory session state.
func LoadSessionState ¶
func LoadSessionState(sessionID string) (*SessionState, error)
LoadSessionState loads a session state and decrypts the tokenSet. Returns nil if there is no existing session.
type TokenSet ¶
type TokenSet struct { IDToken string `json:"id_token"` AccessToken string `json:"access_token"` RefreshToken string `json:"refresh_token"` TokenType string `json:"token_type,omitempty"` Scope string `json:"scope,omitempty"` }
Type for Metaplay Auth. Get this using OAuth2 code exchange with auth.metaplay.dev.
func LoadAndRefreshTokenSet ¶
func LoadAndRefreshTokenSet(authProvider *AuthProviderConfig) (*TokenSet, error)
Load the current token set. If not logged in, just return empty tokens. If logged in and tokens have expired, refresh the tokens. If the refresh fails, return an error. \todo Forget the tokens if the refresh fails (due to keys already used)
type UserInfoResponse ¶
type UserInfoResponse struct { Subject string `json:"sub"` // Same as account.provideAccountId (not portal userID) Email string `json:"email"` Picture string `json:"picture"` GivenName string `json:"given_name"` FamilyName string `json:"family_name"` Name string `json:"name"` Roles []string `json:"https://schemas.metaplay.io/roles"` }
*
- OIDC UserInfo Response object.
- @see https://openid.net/specs/openid-connect-core-1_0.html#UserInfo
func FetchUserInfo ¶
func FetchUserInfo(authProvider *AuthProviderConfig, tokenSet *TokenSet) (*UserInfoResponse, error)