Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add the 'WithClientCredentialsResult' LoginOption #37

Draft
wants to merge 5 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 28 additions & 0 deletions idfabric/idfrabric.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package idfabric

import "net/http"

const (
GrantTypeClientCredentials = iota + 1
)

// IdentityProvider enables a way to interact with the identity provider.
// Interactions may include login and logout.
type IdentityProvider interface {
Expand All @@ -15,6 +19,9 @@ type IdentityProvider interface {
type LoginOptions struct {
Username string
RedirectURL string

GrantType int
LoginResult *LoginResult
}

// LoginOpt allows for customizing the login experience.
Expand All @@ -37,6 +44,27 @@ func WithRedirectURL(url string) LoginOpt {
}
}

type LoginResult struct {
TokenResult
Error error
}

type TokenResult struct {
AccessToken string
Scope string
ExpiresIn int
}

// WithGrantTypeClientCredentials sets the grant type for this Login attempt to
// 'client_credentials'.
// The results of Login will be stored in tokenResult and errorResult.
func WithGrantTypeClientCredentials(result *LoginResult) LoginOpt {
return func(cfg *LoginOptions) {
cfg.GrantType = GrantTypeClientCredentials
cfg.LoginResult = result
}
}

// AttributeProvider is used to retrieve attributes from an external system. A common
// attribute provider would be a data store such as LDAP.
type AttributeProvider interface {
Expand Down