Publish Docker image (Multi-arch) / Build & push (amd64) (push) Failing after 9m20s
Release (Linux, macOS, Windows) / Linux Release (push) Failing after 55m7s
Publish Docker image (Multi-arch) / Build & push (arm64) (push) Canceled after 0s
Release (Linux, macOS, Windows) / macOS Release (push) Canceled after 0s
Release (Linux, macOS, Windows) / Windows Release (push) Canceled after 0s
Publish Docker image (Multi-arch) / Create multi-arch manifests (push) Canceled after 0s
45 lines
1.8 KiB
Go
45 lines
1.8 KiB
Go
package service
|
|
|
|
import "errors"
|
|
|
|
var ErrOAuthAccountMismatch = errors.New("The OAuth account does not match the account linked to your profile.")
|
|
|
|
type OAuthVerificationFlow struct {
|
|
Scope string `json:"scope"`
|
|
ContextHash string `json:"context_hash"`
|
|
ProviderUserID string `json:"provider_user_id"`
|
|
UserAuthVersion int64 `json:"auth_version"`
|
|
SessionVersion int64 `json:"session_version"`
|
|
}
|
|
|
|
func StartOAuthVerification(identity AuthIdentity, operation VerificationOperation, provider string) (*OAuthVerificationFlow, error) {
|
|
binding, err := BindVerificationOperation(operation)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
providerUserID, err := GetOAuthVerificationBinding(identity, binding.Scope, provider)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return &OAuthVerificationFlow{
|
|
Scope: binding.Scope, ContextHash: binding.ContextHash, ProviderUserID: providerUserID,
|
|
UserAuthVersion: identity.UserAuthVersion, SessionVersion: identity.SessionVersion,
|
|
}, nil
|
|
}
|
|
|
|
// FinishOAuthVerification only verifies an existing binding. It deliberately
|
|
// never calls OAuth's login or find-or-create-user paths.
|
|
func FinishOAuthVerification(identity AuthIdentity, provider, actualUserID string, flow *OAuthVerificationFlow) (*SecurityProof, error) {
|
|
if flow == nil || flow.ContextHash == "" || flow.UserAuthVersion != identity.UserAuthVersion || flow.SessionVersion != identity.SessionVersion {
|
|
return nil, ErrAuthTokenInvalid
|
|
}
|
|
expectedUserID, err := GetOAuthVerificationBinding(identity, flow.Scope, provider)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if actualUserID == "" || actualUserID != expectedUserID || actualUserID != flow.ProviderUserID {
|
|
return nil, ErrOAuthAccountMismatch
|
|
}
|
|
return CompleteSecurityVerification(identity, VerificationBinding{Scope: flow.Scope, ContextHash: flow.ContextHash}, VerificationMethodOAuth)
|
|
}
|