-
Notifications
You must be signed in to change notification settings - Fork 968
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: move credential configs for oidc and password
- Loading branch information
Showing
19 changed files
with
181 additions
and
108 deletions.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package identity | ||
|
||
import ( | ||
"bytes" | ||
"encoding/json" | ||
"fmt" | ||
|
||
"github.com/pkg/errors" | ||
|
||
"github.com/ory/kratos/x" | ||
) | ||
|
||
// CredentialsOIDC is contains the configuration for credentials of the type oidc. | ||
// | ||
// swagger:model identityCredentialsOidc | ||
type CredentialsOIDC struct { | ||
Providers []CredentialsOIDCProvider `json:"providers"` | ||
} | ||
|
||
// CredentialsOIDCProvider is contains a specific OpenID COnnect credential for a particular connection (e.g. Google). | ||
// | ||
// swagger:model identityCredentialsOidcProvider | ||
type CredentialsOIDCProvider struct { | ||
Subject string `json:"subject"` | ||
Provider string `json:"provider"` | ||
InitialIDToken string `json:"initial_id_token"` | ||
InitialAccessToken string `json:"initial_access_token"` | ||
InitialRefreshToken string `json:"initial_refresh_token"` | ||
} | ||
|
||
// NewCredentialsOIDC creates a new OIDC credential. | ||
func NewCredentialsOIDC(idToken, accessToken, refreshToken, provider, subject string) (*Credentials, error) { | ||
var b bytes.Buffer | ||
if err := json.NewEncoder(&b).Encode(CredentialsOIDC{ | ||
Providers: []CredentialsOIDCProvider{ | ||
{ | ||
Subject: subject, | ||
Provider: provider, | ||
InitialIDToken: idToken, | ||
InitialAccessToken: accessToken, | ||
InitialRefreshToken: refreshToken, | ||
}}, | ||
}); err != nil { | ||
return nil, errors.WithStack(x.PseudoPanic. | ||
WithDebugf("Unable to encode password options to JSON: %s", err)) | ||
} | ||
|
||
return &Credentials{ | ||
Type: CredentialsTypeOIDC, | ||
Identifiers: []string{OIDCUniqueID(provider, subject)}, | ||
Config: b.Bytes(), | ||
}, nil | ||
} | ||
|
||
func OIDCUniqueID(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package identity | ||
|
||
// CredentialsPassword is contains the configuration for credentials of the type password. | ||
// | ||
// swagger:model identityCredentialsPassword | ||
type CredentialsPassword struct { | ||
// HashedPassword is a hash-representation of the password. | ||
HashedPassword string `json:"hashed_password"` | ||
} |
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
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
Oops, something went wrong.