Quick Start
This guide will help you integrate AuthStack into your application quickly.
Prerequisites
Section titled “Prerequisites”- An AuthStack account
- Your application registered in the AuthStack dashboard
- OAuth providers configured and enabled for your app
1. Get Your Credentials
Section titled “1. Get Your Credentials”- Log in to the AuthStack Dashboard
- Create a new application
- Copy your Client ID
- Enable the OAuth providers you want to use (Google, GitHub, Microsoft, Apple, Discord)
2. Install the SDK
Section titled “2. Install the SDK”Flutter
Section titled “Flutter”flutter pub add voo_authstack_clientdotnet add package AuthStack.Client3. Initialize the Client
Section titled “3. Initialize the Client”Flutter
Section titled “Flutter”import 'package:voo_authstack_client/voo_authstack_client.dart';
final authService = VooAuthstackService( config: VooAuthstackConfig( baseUrl: 'https://api.authstack.voostack.com', ),);
// Initialize (checks for stored tokens)await authService.initialize();using AuthStack.Client;
var client = new AuthStackClient(new AuthStackConfig{ BaseUrl = "https://api.authstack.voostack.com"});
// Initialize (restores any stored session)await client.InitializeAsync();4. Implement Social Login
Section titled “4. Implement Social Login”Using Centralized OAuth (Recommended)
Section titled “Using Centralized OAuth (Recommended)”AuthStack handles OAuth app configuration centrally. Get the authorization URL and redirect users:
Flutter
Section titled “Flutter”// Get OAuth URL for GitHubfinal authUrl = await authService.getProviderAuthUrl( provider: OAuthProvider.github, redirectUri: 'https://yourapp.com/oauth/callback',);
// Redirect user to authUrl.authorizationUrl// After callback, link the provider with the codefinal linked = await authService.linkProviderWithCode( provider: OAuthProvider.github, code: codeFromCallback, redirectUri: 'https://yourapp.com/oauth/callback',);// Get OAuth URL for GitHubvar authUrl = await client.GetProviderAuthUrlAsync( OAuthProvider.GitHub, "https://yourapp.com/oauth/callback");
// Redirect user to authUrl.AuthorizationUrl// After callback, link the provider with the codevar linked = await client.LinkProviderWithCodeAsync( OAuthProvider.GitHub, codeFromCallback, "https://yourapp.com/oauth/callback");Google Sign-In (with your own OAuth app)
Section titled “Google Sign-In (with your own OAuth app)”// Get Google credential from GoogleSignInfinal googleUser = await GoogleSignIn().signIn();final googleAuth = await googleUser?.authentication;
// Exchange for AuthStack tokensfinal result = await authService.loginWithOAuthToken( provider: OAuthProvider.google, token: googleAuth!.idToken!,);
if (authService.isAuthenticated) { print('Logged in as ${result.user.email}');}GitHub Login
Section titled “GitHub Login”// After OAuth redirect with authorization codefinal result = await authService.loginWithOAuthCode( provider: OAuthProvider.github, code: authorizationCode, redirectUri: 'https://yourapp.com/oauth/callback',);All Supported Providers
Section titled “All Supported Providers”// Googleawait authService.loginWithOAuthToken( provider: OAuthProvider.google, token: idToken,);
// GitHubawait authService.loginWithOAuthCode( provider: OAuthProvider.github, code: authorizationCode, redirectUri: redirectUri,);
// Microsoftawait authService.loginWithOAuthCode( provider: OAuthProvider.microsoft, code: authorizationCode, redirectUri: redirectUri,);
// Appleawait authService.loginWithOAuthToken( provider: OAuthProvider.apple, token: identityToken,);
// Discordawait authService.loginWithOAuthCode( provider: OAuthProvider.discord, code: authorizationCode, redirectUri: redirectUri,);5. Email/Password Login
Section titled “5. Email/Password Login”Flutter
Section titled “Flutter”try { final result = await authService.loginWithEmail( email: 'user@example.com', password: 'password123', ); print('Logged in as ${result.user.email}');} on VooAuthstackException catch (e) { print('Login failed: ${e.message}');}var result = await client.LoginAsync("user@example.com", "password123");
if (result.IsSuccess){ Console.WriteLine($"Logged in as {result.User!.Email}");}else{ Console.WriteLine($"Login failed: {result.Error}");}6. Get Provider Credentials
Section titled “6. Get Provider Credentials”After linking a provider, get their access token to make API calls:
Flutter
Section titled “Flutter”// Get GitHub credentialsfinal credentials = await authService.getProviderCredentials( OAuthProvider.github,);
// Use the access token with GitHub APIfinal response = await http.get( Uri.parse('https://api.github.com/user/repos'), headers: {'Authorization': 'Bearer ${credentials.accessToken}'},);// Get GitHub credentialsvar credentials = await client.GetProviderCredentialsAsync(OAuthProvider.GitHub);
// Use with Octokit (GitHub .NET SDK)var github = new GitHubClient(new ProductHeaderValue("MyApp"));github.Credentials = new Credentials(credentials.AccessToken);var repos = await github.Repository.GetAllForCurrent();7. Listen to Auth State Changes
Section titled “7. Listen to Auth State Changes”Flutter
Section titled “Flutter”authService.statusStream.listen((status) { switch (status) { case AuthStatus.authenticated: print('User is logged in'); break; case AuthStatus.unauthenticated: print('User is logged out'); break; case AuthStatus.authenticating: print('Login in progress...'); break; }});client.StatusChanged += (sender, status) =>{ Console.WriteLine($"Auth status changed: {status}");};
client.UserChanged += (sender, user) =>{ if (user != null) Console.WriteLine($"Current user: {user.FullName}");};8. Protect Routes
Section titled “8. Protect Routes”Use the tokens to authenticate API requests:
Flutter
Section titled “Flutter”final dio = Dio();dio.options.headers['Authorization'] = 'Bearer ${authService.currentTokens?.accessToken}';var httpClient = new HttpClient();httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", client.AccessToken);Next Steps
Section titled “Next Steps”- Installation - Detailed installation guide
- Concepts - Understand tokens and sessions
- OAuth 2.0 Authorization - Implement OAuth flows with PKCE
- Applications API - Manage OAuth applications