oidcsdk

package module
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Jul 20, 2020 License: Apache-2.0 Imports: 7 Imported by: 8

README

github.com/identityOrg/oidcsdk

An attempt to create a SDK for OAuth2 and OpenID Connect protocol

Documentation

Index

Constants

View Source
const (
	GrantAuthorizationCode     = "authorization_code"
	GrantImplicit              = "implicit"
	GrantResourceOwnerPassword = "password"
	GrantClientCredentials     = "client_credentials"
	GrantRefreshToken          = "refresh_token"
)
View Source
const (
	ScopeOpenid        = "openid"
	ScopeProfile       = "profile"
	ScopeEmail         = "email"
	ScopeAddress       = "address"
	ScopeOfflineAccess = "offline_access"
)
View Source
const (
	ResponseTypeCode    = "code"
	ResponseTypeToken   = "token"
	ResponseTypeIdToken = "id_token"
)
View Source
const (
	ResponseModeQuery    = "query"
	ResponseModeFragment = "fragment"
	ResponseModeFormPost = "form"
)
View Source
const (
	ContentTypeUrlEncodedForm = "application/x-www-form-urlencoded"
	ContentTypeJson           = "application/json"
	ContentTypeHtml           = "text/html"
)
View Source
const (
	HeaderContentType   = "Content-Type"
	HeaderAuthorization = "Authorization"
)
View Source
const (
	ExpireAuthorizationCode = 1
	ExpireAccessToken       = 2
	ExpireRefreshToken      = 4
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Arguments

type Arguments []string

func (Arguments) Exact deprecated

func (r Arguments) Exact(name string) bool

Deprecated: Use ExactOne, Matches or MatchesExact

func (Arguments) ExactOne

func (r Arguments) ExactOne(name string) bool

ExactOne checks, by string case, that a single argument equals the provided string.

func (Arguments) Has

func (r Arguments) Has(items ...string) bool

Has checks, in a case-insensitive manner, that all of the items provided exists in arguments.

func (Arguments) HasOneOf

func (r Arguments) HasOneOf(items ...string) bool

HasOneOf checks, in a case-insensitive manner, that one of the items provided exists in arguments.

func (Arguments) Matches

func (r Arguments) Matches(items ...string) bool

Matches performs an case-insensitive, out-of-order check that the items provided exist and equal all of the args in arguments. Note:

  • Providing a list that includes duplicate string-case items will return not matched.

func (Arguments) MatchesExact

func (r Arguments) MatchesExact(items ...string) bool

MatchesExact checks, by order and string case, that the items provided equal those in arguments.

func (Arguments) String

func (r Arguments) String() string

type AuthenticationRequestContextFactory

type AuthenticationRequestContextFactory func(request *http.Request) (IAuthenticationRequestContext, IError)

type AuthenticationResponseWriter

type AuthenticationResponseWriter func(requestContext IAuthenticationRequestContext, w http.ResponseWriter, r *http.Request) error

type Config

type Config struct {
	Issuer                   string
	AuthCodeLifespan         time.Duration
	AccessTokenLifespan      time.Duration
	RefreshTokenLifespan     time.Duration
	AccessTokenEntropy       int
	AuthorizationCodeEntropy int
	RefreshTokenEntropy      int
	StateParamMinimumEntropy int
	GlobalConsentRequired    bool
}

func NewConfig

func NewConfig(issuer string) *Config

type ErrorFactory

type ErrorFactory func(status uint8, code string, description string) IError

type ErrorStrategy

type ErrorStrategy func(err error, w http.ResponseWriter)

type IAccessTokenStrategy

type IAccessTokenStrategy interface {
	GenerateAccessToken() (token string, signature string)
	SignAccessToken(token string) (signature string, err error)
}

type IAuthEPHandler

type IAuthEPHandler interface {
	HandleAuthEP(ctx context.Context, requestContext IAuthenticationRequestContext) IError
}

type IAuthenticationRequestContext

type IAuthenticationRequestContext interface {
	IRequestContext
	GetUserSession() ISession
	SetUserSession(sess ISession)
	GetNonce() string
	GetResponseMode() string
	GetResponseType() Arguments
	SetRedirectURI(uri string)
	IssueAuthorizationCode(code string, signature string, expiry time.Time)
}

type IAuthorizationCodeStrategy

type IAuthorizationCodeStrategy interface {
	GenerateAuthCode() (code string, signature string)
	SignAuthCode(token string) (signature string, err error)
}

type IBaseContext

type IBaseContext interface {
	GetRequestID() string
	GetRequestedAt() time.Time
	GetClientID() string
	SetClient(client IClient)
	GetSecret() string
	GetClient() IClient
	GetError() IError
	SetError(err IError)
	GetForm() *url.Values
}

type IClient

type IClient interface {
	GetID() string
	GetSecret() string
	IsPublic() bool
	GetIDTokenSigningAlg() jose.SignatureAlgorithm
	GetRedirectURIs() []string
	GetApprovedScopes() Arguments
	GetApprovedGrantTypes() Arguments
}

type IClientStore

type IClientStore interface {
	GetClient(ctx context.Context, clientID string) (client IClient, err error)
	FetchClientProfile(ctx context.Context, clientID string) RequestProfile
}

type IConfigurable

type IConfigurable interface {
	Configure(strategy interface{}, config *Config, arg ...interface{})
}

type IError

type IError interface {
	error
	GetStatus() string
	GetReason() string
	GetStatusCode() int
	GetDescription() string
	GetDebugInfo() string
}

type IIDTokenStrategy

type IIDTokenStrategy interface {
	GenerateIDToken(profile RequestProfile, client IClient, expiry time.Time,
		transactionClaims map[string]interface{}) (idToken string, err error)
}

type IIntrospectionRequestContext

type IIntrospectionRequestContext interface {
	IBaseContext
	GetProfile() RequestProfile
	SetProfile(profile RequestProfile)
	GetToken() string
	GetTokenTypeHint() string
}

type IManager

type IManager interface {
	ProcessAuthorizationEP(w http.ResponseWriter, r *http.Request)
	ProcessTokenEP(w http.ResponseWriter, r *http.Request)
	ProcessIntrospectionEP(w http.ResponseWriter, r *http.Request)
	ProcessRevocationEP(w http.ResponseWriter, r *http.Request)
}

type IRefreshTokenStrategy

type IRefreshTokenStrategy interface {
	GenerateRefreshToken() (token string, signature string)
	SignRefreshToken(token string) (signature string, err error)
}

type IRequestContext

type IRequestContext interface {
	GetRequestID() string
	GetRequestedAt() time.Time
	GetState() string
	GetRedirectURI() string
	GetClientID() string
	GetRequestedScopes() Arguments
	GetRequestedAudience() Arguments
	GetClaims() map[string]interface{}
	GetClient() IClient
	SetClient(client IClient)
	GetProfile() RequestProfile
	SetProfile(profile RequestProfile)
	GetIssuedTokens() Tokens
	IssueAccessToken(token string, signature string, expiry time.Time)
	IssueRefreshToken(token string, signature string, expiry time.Time)
	IssueIDToken(token string)
	GetError() IError
	SetError(err IError)
	GetForm() *url.Values
}

type IRevocationRequestContext

type IRevocationRequestContext interface {
	IBaseContext
	GetToken() string
	GetTokenTypeHint() string
}

type ISession

type ISession interface {
	GetUsername() string
	GetLoginTime() *time.Time
	IsConsentSubmitted() bool
	IsLoginDone() bool
	GetApprovedScopes() Arguments
	GetScope() string
}

type ISessionManager

type ISessionManager interface {
	RetrieveUserSession(r *http.Request) (ISession, error)
}

type ITokenEPHandler

type ITokenEPHandler interface {
	HandleTokenEP(ctx context.Context, requestContext ITokenRequestContext) IError
}

type ITokenRequestContext

type ITokenRequestContext interface {
	IRequestContext
	GetRefreshToken() string
	GetPreviousRequestID() (id string)
	SetPreviousRequestID(id string)
	GetGrantType() string
	GetClientSecret() string
	GetAuthorizationCode() string
	GetUsername() string
	GetPassword() string
}

type ITokenStore

type ITokenStore interface {
	StoreTokenProfile(ctx context.Context, reqId string, signatures TokenSignatures, profile RequestProfile) (err error)
	GetProfileWithAuthCodeSign(ctx context.Context, signature string) (profile RequestProfile, reqId string, err error)
	GetProfileWithAccessTokenSign(ctx context.Context, signature string) (profile RequestProfile, reqId string, err error)
	GetProfileWithRefreshTokenSign(ctx context.Context, signature string) (profile RequestProfile, reqId string, err error)
	InvalidateWithRequestID(ctx context.Context, reqID string, what uint8) (err error)
}

type ITransactionalStore

type ITransactionalStore interface {
	StartTransaction(ctx context.Context)
	CommitTransaction(ctx context.Context)
	RollbackTransaction(ctx context.Context)
}

type IUserStore

type IUserStore interface {
	Authenticate(ctx context.Context, username string, credential []byte) (err error)
	GetClaims(ctx context.Context, username string, scopes Arguments, claimsIDs []string) (map[string]interface{}, error)
	IsConsentRequired(ctx context.Context, username string, clientId string, scopes Arguments) bool
	StoreConsent(ctx context.Context, username string, clientId string, scopes Arguments) error
	FetchUserProfile(ctx context.Context, username string) RequestProfile
}

type IntrospectionRequestContextFactory

type IntrospectionRequestContextFactory func(r *http.Request) (IRevocationRequestContext, IError)

type IntrospectionResponseWriter

type IntrospectionResponseWriter func(requestContext IRevocationRequestContext, w http.ResponseWriter, r *http.Request) error

type JsonErrorWriter

type JsonErrorWriter func(requestContext ITokenRequestContext, w http.ResponseWriter, r *http.Request) error

type RedirectErrorWriter

type RedirectErrorWriter func(requestContext IAuthenticationRequestContext, w http.ResponseWriter, r *http.Request) error

type RequestProfile

type RequestProfile map[string]string

func NewRequestProfile

func NewRequestProfile() RequestProfile

func (RequestProfile) GetAudience

func (r RequestProfile) GetAudience() Arguments

func (RequestProfile) GetClientID

func (r RequestProfile) GetClientID() string

func (RequestProfile) GetDomain

func (r RequestProfile) GetDomain() string

func (RequestProfile) GetNonce

func (r RequestProfile) GetNonce() string

func (RequestProfile) GetRedirectURI

func (r RequestProfile) GetRedirectURI() string

func (RequestProfile) GetScope

func (r RequestProfile) GetScope() Arguments

func (RequestProfile) GetState

func (r RequestProfile) GetState() string

func (RequestProfile) GetUsername

func (r RequestProfile) GetUsername() string

func (RequestProfile) IsClient

func (r RequestProfile) IsClient() bool

func (RequestProfile) SetAudience

func (r RequestProfile) SetAudience(aud Arguments)

func (RequestProfile) SetClientID

func (r RequestProfile) SetClientID(username string)

func (RequestProfile) SetDomain

func (r RequestProfile) SetDomain(domain string)

func (RequestProfile) SetNonce

func (r RequestProfile) SetNonce(nonce string)

func (RequestProfile) SetRedirectURI

func (r RequestProfile) SetRedirectURI(redirectUri string)

func (RequestProfile) SetScope

func (r RequestProfile) SetScope(scopes Arguments)

func (RequestProfile) SetState

func (r RequestProfile) SetState(state string)

func (RequestProfile) SetUsername

func (r RequestProfile) SetUsername(username string)

type RevocationRequestContextFactory

type RevocationRequestContextFactory func(r *http.Request) (IRevocationRequestContext, IError)

type RevocationResponseWriter

type RevocationResponseWriter func(requestContext IRevocationRequestContext, w http.ResponseWriter, r *http.Request) error

type TokenRequestContextFactory

type TokenRequestContextFactory func(request *http.Request) (ITokenRequestContext, IError)

type TokenResponseWriter

type TokenResponseWriter func(requestContext ITokenRequestContext, w http.ResponseWriter, r *http.Request) error

type TokenSignatures

type TokenSignatures struct {
	AuthorizationCodeSignature string
	AccessTokenSignature       string
	RefreshTokenSignature      string
	RefreshTokenExpiry         time.Time
	AccessTokenExpiry          time.Time
	AuthorizationCodeExpiry    time.Time
}

type Tokens

type Tokens struct {
	TokenSignatures
	AuthorizationCode string
	AccessToken       string
	RefreshToken      string
	TokenType         string
	IDToken           string
}

Directories

Path Synopsis
impl

Jump to

Keyboard shortcuts

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