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 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 .
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 can access the system authentication helpers and register the default web session once:
@Environment(\.webAuthenticationSession) private var webAuthenticationSession
@Environment(\.authorizationController) private var authorizationController
var body: some View {
VStack { /* auth UI */ }
.task {
paraManager.setDefaultWebAuthenticationSession(webAuthenticationSession)
}
}
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()
.task {
paraManager.setDefaultWebAuthenticationSession(webAuthenticationSession)
}
}
}
Handling Social Login
Implement the social login handler that manages the OAuth flow:
private func handleSocialLogin(_ provider: OAuthProvider) {
Task {
do {
try await paraManager.handleOAuth(
provider: provider,
authorizationController: authorizationController
)
// OAuth flow completed successfully
// User is now logged in and wallets are available
print("User authenticated successfully")
// Navigate to authenticated area of your app
} catch {
// Handle OAuth error
print("OAuth 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 nothing on success, throws errors on failure
- Uses the default
WebAuthenticationSession you registered; pass a custom one only if you need to override it for a specific call.
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:
- for new users
- for session management
- as an additional security layer