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 account linking configs #4149

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
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
88 changes: 84 additions & 4 deletions pkg/lib/config/authentication_flow.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ var _ = Schema.Add("AuthenticationFlowConfig", `
"minItems": 1,
"items": { "$ref": "#/$defs/AuthenticationFlowAccountRecoveryFlow" }
},
"rate_limits": { "$ref": "#/$defs/AuthenticationFlowRateLimitsConfig" }
"rate_limits": { "$ref": "#/$defs/AuthenticationFlowRateLimitsConfig" },
"default_account_linking": { "$ref": "#/$defs/AuthenticationFlowAccountLinking" }
}
}
`)
Expand Down Expand Up @@ -72,6 +73,7 @@ var _ = Schema.Add("AuthenticationFlowSignupFlow", `
"required": ["name", "steps"],
"properties": {
"name": { "$ref": "#/$defs/AuthenticationFlowObjectName" },
"account_linking": { "$ref": "#/$defs/AuthenticationFlowAccountLinking" },
"steps": {
"type": "array",
"minItems": 1,
Expand Down Expand Up @@ -624,6 +626,56 @@ var _ = Schema.Add("AuthenticationFlowAccountRecoveryIdentification", `
}
`)

var _ = Schema.Add("AuthenticationFlowAccountLinking", `
{
"type": "object",
"required": [],
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Omit required.

"properties": {
"oauth": {
"type": "array",
"items": { "$ref": "#/$defs/AccountLinkingOAuth" }
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name the schema AuthenticationFlowAccountLinkOAuthItem

}
}
}
`)

var _ = Schema.Add("AccountLinkingOAuth", `
{
"type": "object",
"required": ["alias", "oauth_claim", "user_profile", "action"],
"properties": {
"alias": { "type": "string" },
"oauth_claim": { "$ref": "#/$defs/AccountLinkingJSONPointer" },
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Name the schema AuthenticationFlowAccountLinkingJSONPointer

"user_profile": { "$ref": "#/$defs/AccountLinkingJSONPointer" },
"action": { "$ref": "#/$defs/AccountLinkingOAuthAction" },
"login_flow": { "type": "string" }
}
}
`)

var _ = Schema.Add("AccountLinkingOAuthAction", `
{
"type": "string",
"enum": [
"error",
"login_and_link"
]
}
`)

var _ = Schema.Add("AccountLinkingJSONPointer", `
{
"type": "object",
"additionalProperties": false,
"properties": {
"pointer": {
"type": "string",
"format": "json-pointer"
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add "required": ["pointer"]

}
`)

type AuthenticationFlowObject interface {
IsFlowObject()
}
Expand Down Expand Up @@ -798,12 +850,14 @@ type AuthenticationFlowConfig struct {
ReauthFlows []*AuthenticationFlowReauthFlow `json:"reauth_flows,omitempty"`
AccountRecoveryFlows []*AuthenticationFlowAccountRecoveryFlow `json:"account_recovery_flows,omitempty"`

RateLimits *AuthenticationFlowRateLimitsConfig `json:"rate_limits,omitempty"`
RateLimits *AuthenticationFlowRateLimitsConfig `json:"rate_limits,omitempty"`
DefaultAccountLinking *AuthenticationFlowAccountLinking `json:"default_account_linking,omitempty"`
}

type AuthenticationFlowSignupFlow struct {
Name string `json:"name,omitempty"`
Steps []*AuthenticationFlowSignupFlowStep `json:"steps,omitempty"`
Name string `json:"name,omitempty"`
AccountLinking *AuthenticationFlowAccountLinking `json:"account_linking,omitempty"`
Steps []*AuthenticationFlowSignupFlowStep `json:"steps,omitempty"`
}

var _ AuthenticationFlowObjectFlowRoot = &AuthenticationFlowSignupFlow{}
Expand Down Expand Up @@ -1332,6 +1386,32 @@ const (
AuthenticationFlowAccountRecoveryIdentificationOnFailureIgnore = AuthenticationFlowAccountRecoveryIdentificationOnFailure("ignore")
)

type AuthenticationFlowAccountLinking struct {
OAuth []*AccountLinkingOAuth `json:"oauth,omitempty"`
}

type AccountLinkingOAuth struct {
Alias string `json:"alias,omitempty"`
OAuthClaim AccountLinkingJSONPointer `json:"oauth_claim,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a pointer to AccountLinkingJSONPointer

UserProfile AccountLinkingJSONPointer `json:"user_profile,omitempty"`
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be a pointer to AccountLinkingJSONPointer

Action AccountLinkingOAuthAction `json:"action,omitempty"`

// login_flow is only relevant if action is "login_and_link"
// If empty, the current flow name should be used
LoginFlow string `json:"login_flow,omitempty"`
}

type AccountLinkingOAuthAction string

const (
AccountLinkingOAuthActionError AccountLinkingOAuthAction = "error"
AccountLinkingOAuthActionLoginAndLink AccountLinkingOAuthAction = "login_andLink"
)

type AccountLinkingJSONPointer struct {
Pointer string `json:"pointer,omitempty"`
}

func init() {
accountRecoveryChannelsOneOf := ""
addAccountRecoveryChannel := func(channel AccountRecoveryCodeChannel, otpForm AccountRecoveryCodeForm) {
Expand Down
1 change: 1 addition & 0 deletions pkg/lib/config/testdata/default_config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,7 @@ test_mode:
email:
enabled: false
authentication_flow:
default_account_linking: {}
rate_limits:
per_ip:
enabled: true
Expand Down
Loading