Merge pull request 'feat: sign up and sign in with platform identity providers' (#123) from feat/platform-sso into main
This commit was merged in pull request #123.
This commit is contained in:
commit
29b9e1ce2b
26 files changed
+2710
-351
No files matched your search
+16
-1
@@ -16,8 +16,10 @@ import (
|
||||
"golang.org/x/oauth2"
|
||||
)
|
||||
|
||||
// Provider is one organization's IdP registration.
|
||||
// Provider is an IdP registration, of an organization or the platform.
|
||||
type Provider struct {
|
||||
// Kind is empty for OpenID Connect or GitHub.
|
||||
Kind string
|
||||
Issuer string
|
||||
ClientID string
|
||||
ClientSecret string
|
||||
@@ -91,6 +93,9 @@ func (c *Client) ValidateIssuer(ctx context.Context, issuer string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
// CheckURL checks that a server URL may be used, without contacting it.
|
||||
func (c *Client) CheckURL(issuer string) error { return c.checkIssuer(issuer) }
|
||||
|
||||
func (c *Client) checkIssuer(issuer string) error {
|
||||
u, err := url.Parse(issuer)
|
||||
if err != nil || u.Host == "" || u.RawQuery != "" || u.Fragment != "" || u.User != nil {
|
||||
@@ -144,6 +149,9 @@ func (c *Client) AuthURL(ctx context.Context, p Provider, f Flow) (string, error
|
||||
if err := c.checkIssuer(p.Issuer); err != nil {
|
||||
return "", err
|
||||
}
|
||||
if p.Kind == GitHub {
|
||||
return c.githubOAuth(p).AuthCodeURL(f.State, oauth2.S256ChallengeOption(f.Verifier)), nil
|
||||
}
|
||||
op, err := c.discover(ctx, p.Issuer)
|
||||
if err != nil {
|
||||
return "", err
|
||||
@@ -157,6 +165,13 @@ func (c *Client) AuthURL(ctx context.Context, p Provider, f Flow) (string, error
|
||||
// Exchange redeems the authorization code and verifies the ID token's
|
||||
// signature, issuer, audience, expiry and nonce.
|
||||
func (c *Client) Exchange(ctx context.Context, p Provider, f Flow, code string) (Claims, error) {
|
||||
if p.Kind == GitHub {
|
||||
tok, err := c.githubOAuth(p).Exchange(oidc.ClientContext(ctx, c.http), code, oauth2.VerifierOption(f.Verifier))
|
||||
if err != nil {
|
||||
return Claims{}, fmt.Errorf("sso: code exchange: %w", err)
|
||||
}
|
||||
return c.githubClaims(ctx, p, tok)
|
||||
}
|
||||
op, err := c.discover(ctx, p.Issuer)
|
||||
if err != nil {
|
||||
return Claims{}, err
|
||||
|
||||
Reference in new issue
Block a user