Overview

Social login (OAuth) is integrated directly into Para’s unified authentication experience. This guide covers how to implement social login alongside email and phone authentication in a single, streamlined interface. Para supports Google, Apple, and Discord as OAuth providers.

Prerequisites

Prerequisites

To use Para, you need an API key. This key authenticates your requests to Para services and is essential for integration.

Don’t have an API key yet? Request access to the Developer Portal to create API keys, manage billing, teams, and more.

You must have the ParaSwift SDK installed and configured in your project. If you haven’t done this yet, please refer to our Quick Start Guide.

Unified Authentication Approach

Para’s recommended approach is to integrate social login directly into your main authentication view alongside email and phone options. This provides users with all authentication methods in one place.

Environment Setup

Ensure your authentication view has access to the required environment values:

@Environment(\.webAuthenticationSession) private var webAuthenticationSession
@Environment(\.authorizationController) private var authorizationController

Implementing Social Login

Integration with Unified Auth View

Social login should be integrated alongside email and phone authentication in your main authentication view. Here’s a basic example:

import SwiftUI
import ParaSwift
import AuthenticationServices

struct AuthView: View {
    @EnvironmentObject var paraManager: ParaManager
    
    @Environment(\.webAuthenticationSession) private var webAuthenticationSession
    @Environment(\.authorizationController) private var authorizationController
    
    @State private var emailOrPhone = ""
    
    var body: some View {
        VStack(spacing: 20) {
            // Email/Phone input
            TextField("Email or phone number", text: $emailOrPhone)
                .textFieldStyle(RoundedBorderTextFieldStyle())
            
            Button("Continue") {
                handleEmailPhoneAuth()
            }
            .buttonStyle(.borderedProminent)
            
            // Divider
            Text("or")
                .foregroundColor(.gray)
            
            // Social login buttons
            Button("Continue with Google") {
                handleSocialLogin(.google)
            }
            
            Button("Continue with Apple") {
                handleSocialLogin(.apple)
            }
            
            Button("Continue with Discord") {
                handleSocialLogin(.discord)
            }
        }
        .padding()
    }
}

Handling Social Login

Implement the social login handler that manages the OAuth flow:

private func handleSocialLogin(_ provider: OAuthProvider) {
    Task {
        do {
            let result = await paraManager.handleOAuth(
                provider: provider,
                webAuthenticationSession: webAuthenticationSession,
                authorizationController: authorizationController
            )
            
            if result.success {
                // OAuth flow completed successfully
                // User is now logged in and wallets are available
                print("User authenticated successfully")
                // Navigate to authenticated area of your app
            } else {
                // Handle OAuth error
                print("OAuth error: \(result.errorMessage ?? "Unknown error")")
            }
        } catch {
            // Handle error
            print("Error: \(error.localizedDescription)")
        }
    }
}

The handleOAuth method:

  • Authenticates the user with the OAuth provider
  • Checks if a Para account exists for the user
  • For new users: creates a Para account and sets up a passkey automatically
  • For existing users: logs them in directly
  • Returns a success/failure result with any error message

Creating Social Login Buttons

Create buttons for each OAuth provider:

// Google Login
Button("Continue with Google") {
    handleSocialLogin(.google)
}

// Apple Login  
Button("Continue with Apple") {
    handleSocialLogin(.apple)
}

// Discord Login
Button("Continue with Discord") {
    handleSocialLogin(.discord)
}

Available OAuth Providers

The ParaSwift SDK supports the following OAuth providers:

  • Google (.google)
  • Apple (.apple)
  • Discord (.discord)

Key Points

  • Social login is handled through the handleOAuth method
  • The method manages the complete OAuth flow including user authentication, Para account creation/lookup, and passkey setup for new users
  • For existing users, it logs them in directly
  • The SDK supports Google, Apple, and Discord as OAuth providers
  • Social login should be integrated with email/phone authentication for a unified experience

Next Steps

After implementing social login, you might want to:

  1. Set up email verification for new users
  2. Implement secure storage for session management
  3. Add biometric authentication as an additional security layer