Manage Linked Accounts

Allow users to connect and disconnect social accounts from their profile.

Overview

Users can:

  • Link multiple social providers to one account

  • Unlink social providers they no longer want

  • Sign in with any linked provider

Linking Accounts

Automatic Linking

When a user signs in with a social provider:

  1. New user: Account created automatically with social provider linked

  2. Existing user (same email): Social provider linked to existing account

  3. Signed-in user: Social provider added to their account

Manual Linking

For signed-in users to add a social provider:

The user will:

  1. Authenticate with the social provider

  2. Return to Authority with provider linked

  3. Continue with their existing session

Unlinking Accounts

API Endpoint

Request:

Response (Success):

Response (Error):

Safety Checks

Authority prevents unlinking when:

  • It's the user's only login method

  • User has no password set

  • Would leave account inaccessible

Solution: User must set a password or link another provider first.

User Interface

Account Settings Page

Show users their linked accounts:

Example UI

JavaScript Handler

Security Considerations

Account Takeover Prevention

When linking accounts, Authority verifies:

  1. Email match: Social account email matches existing account

  2. Session valid: User is properly authenticated

  3. State parameter: CSRF protection via state validation

Multiple Accounts Warning

If a social account is already linked to a different user:

The user must unlink from the other account first.

Audit Logging

All link/unlink operations are recorded:

Data Stored

For each linked social account:

Field
Description

provider

Provider name (google, github, etc.)

provider_user_id

Unique ID from provider

email

Email from provider

name

Name from provider

avatar_url

Profile picture URL

access_token

Provider access token (encrypted)

refresh_token

Provider refresh token (encrypted)

token_expires_at

Token expiration time

Best Practices

  1. Show linked status - Display which providers are connected

  2. Confirm unlinking - Require user confirmation

  3. Explain consequences - Warn if unlinking removes login method

  4. Update UI immediately - Reflect changes without page reload

  5. Log actions - Track for security auditing

Next Steps

Last updated

Was this helpful?