-
Notifications
You must be signed in to change notification settings - Fork 978
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Registration strategy until redirect to external provider
- Loading branch information
Showing
21 changed files
with
959 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package identity | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/ory/kratos/x" | ||
) | ||
|
||
// CredentialsOid2 contains the configuration for credentials of the type oidc. | ||
// | ||
// swagger:model identityCredentialsOidc | ||
type CredentialsOid2 struct { | ||
Providers []CredentialsOid2Provider `json:"providers"` | ||
} | ||
|
||
// CredentialsOid2 Provider contains a specific OpenID 2.0 credential for a particular connection (e.g. Steam). | ||
// | ||
// swagger:model identityCredentialsOid2Provider | ||
type CredentialsOid2Provider struct { | ||
ClaimedId string `json:"claimed_id"` | ||
Provider string `json:"provider"` | ||
} | ||
|
||
// NewCredentialsOid2 creates a new Open ID 2.0 credential. | ||
func NewCredentialsOid2(claimedId, provider string) (*Credentials, error) { | ||
if provider == "" { | ||
return nil, errors.New("received empty provider in oid2 credentials") | ||
} | ||
|
||
if claimedId == "" { | ||
return nil, errors.New("received empty claimed ID in oid2 credentials") | ||
} | ||
|
||
var b bytes.Buffer | ||
if err := json.NewEncoder(&b).Encode(CredentialsOid2{ | ||
Providers: []CredentialsOid2Provider{ | ||
{ | ||
ClaimedId: claimedId, | ||
Provider: provider, | ||
}}, | ||
}); err != nil { | ||
return nil, errors.WithStack(x.PseudoPanic. | ||
WithDebugf("Unable to encode password options to JSON: %s", err)) | ||
} | ||
|
||
return &Credentials{ | ||
Type: CredentialsTypeOID2, | ||
Identifiers: []string{Oid2UniqueID(provider, claimedId)}, | ||
Config: b.Bytes(), | ||
}, nil | ||
} | ||
|
||
func Oid2UniqueID(provider, subject string) string { | ||
return fmt.Sprintf("%s:%s", provider, subject) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
{ | ||
"$id": "https://schemas.ory.sh/kratos/selfservice/strategy/password/login.schema.json", | ||
"$schema": "http://json-schema.org/draft-07/schema#", | ||
"type": "object", | ||
"properties": { | ||
"csrf_token": { | ||
"type": "string" | ||
}, | ||
"provider": { | ||
"type": "string", | ||
"minLength": 1 | ||
}, | ||
"traits": { | ||
"description": "DO NOT DELETE THIS FIELD. This field will be overwritten in login.go's and registration.go's decoder() method. Do not add anything to this field as it has no effect." | ||
}, | ||
"method": { | ||
"type": "string" | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oid2 | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/ory/x/urlx" | ||
"net/url" | ||
"strings" | ||
) | ||
|
||
type Provider interface { | ||
Config() *Configuration | ||
GetRedirectUrl(ctx context.Context) string | ||
} | ||
|
||
func (providerConfig Configuration) Redir(public *url.URL) string { | ||
return urlx.AppendPaths(public, strings.Replace(RouteCallback, ":provider", providerConfig.ID, 1)).String() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
// Copyright © 2024 Ory Corp | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package oid2 | ||
|
||
import ( | ||
"github.com/ory/herodot" | ||
"github.com/pkg/errors" | ||
"golang.org/x/exp/maps" | ||
) | ||
|
||
type Configuration struct { | ||
// ID is the provider's ID | ||
ID string `json:"id"` | ||
|
||
// Provider is either "generic" for a generic OpenID 2.0 Provider or one of: | ||
// - generic | ||
// - steam | ||
Provider string `json:"provider"` | ||
|
||
// Label represents an optional label which can be used in the UI generation. | ||
Label string `json:"label"` | ||
|
||
// DiscoveryUrl is the URL of the Open ID 2.0 discovery document, typically something like: | ||
// https://example.org/openid. Should only be used and when `provider` is set to `generic`. | ||
DiscoveryUrl string `json:"discovery_url"` | ||
} | ||
|
||
type ConfigurationCollection struct { | ||
BaseRedirectURI string `json:"base_redirect_uri"` | ||
Providers []Configuration `json:"providers"` | ||
} | ||
|
||
var supportedProviders = map[string]func(config *Configuration, reg Dependencies) Provider{ | ||
"generic": NewProviderGenericOid2, | ||
"steam": NewProviderSteam, | ||
} | ||
|
||
func (c ConfigurationCollection) Provider(id string, reg Dependencies) (Provider, error) { | ||
for k := range c.Providers { | ||
p := c.Providers[k] | ||
if p.ID == id { | ||
if f, ok := supportedProviders[p.Provider]; ok { | ||
return f(&p, reg), nil | ||
} | ||
|
||
return nil, errors.Errorf("provider type %s is not supported, supported are: %v", p.Provider, maps.Keys(supportedProviders)) | ||
} | ||
} | ||
return nil, errors.WithStack(herodot.ErrNotFound.WithReasonf(`OpenID 2.0 Provider "%s" is unknown or has not been configured`, id)) | ||
} |
Oops, something went wrong.