Skip to content

Quick Start

This guide will help you integrate AuthStack into your application quickly.

  • An AuthStack account
  • Your application registered in the AuthStack dashboard
  • OAuth providers configured and enabled for your app
  1. Log in to the AuthStack Dashboard
  2. Create a new application
  3. Copy your Client ID
  4. Enable the OAuth providers you want to use (Google, GitHub, Microsoft, Apple, Discord)
Terminal window
flutter pub add voo_authstack_client
Terminal window
dotnet add package AuthStack.Client
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();

AuthStack handles OAuth app configuration centrally. Get the authorization URL and redirect users:

// Get OAuth URL for GitHub
final 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 code
final linked = await authService.linkProviderWithCode(
provider: OAuthProvider.github,
code: codeFromCallback,
redirectUri: 'https://yourapp.com/oauth/callback',
);
// Get OAuth URL for GitHub
var authUrl = await client.GetProviderAuthUrlAsync(
OAuthProvider.GitHub,
"https://yourapp.com/oauth/callback"
);
// Redirect user to authUrl.AuthorizationUrl
// After callback, link the provider with the code
var linked = await client.LinkProviderWithCodeAsync(
OAuthProvider.GitHub,
codeFromCallback,
"https://yourapp.com/oauth/callback"
);
// Get Google credential from GoogleSignIn
final googleUser = await GoogleSignIn().signIn();
final googleAuth = await googleUser?.authentication;
// Exchange for AuthStack tokens
final result = await authService.loginWithOAuthToken(
provider: OAuthProvider.google,
token: googleAuth!.idToken!,
);
if (authService.isAuthenticated) {
print('Logged in as ${result.user.email}');
}
// After OAuth redirect with authorization code
final result = await authService.loginWithOAuthCode(
provider: OAuthProvider.github,
code: authorizationCode,
redirectUri: 'https://yourapp.com/oauth/callback',
);
// Google
await authService.loginWithOAuthToken(
provider: OAuthProvider.google,
token: idToken,
);
// GitHub
await authService.loginWithOAuthCode(
provider: OAuthProvider.github,
code: authorizationCode,
redirectUri: redirectUri,
);
// Microsoft
await authService.loginWithOAuthCode(
provider: OAuthProvider.microsoft,
code: authorizationCode,
redirectUri: redirectUri,
);
// Apple
await authService.loginWithOAuthToken(
provider: OAuthProvider.apple,
token: identityToken,
);
// Discord
await authService.loginWithOAuthCode(
provider: OAuthProvider.discord,
code: authorizationCode,
redirectUri: redirectUri,
);
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}");
}

After linking a provider, get their access token to make API calls:

// Get GitHub credentials
final credentials = await authService.getProviderCredentials(
OAuthProvider.github,
);
// Use the access token with GitHub API
final response = await http.get(
Uri.parse('https://api.github.com/user/repos'),
headers: {'Authorization': 'Bearer ${credentials.accessToken}'},
);
// Get GitHub credentials
var 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();
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}");
};

Use the tokens to authenticate API requests:

final dio = Dio();
dio.options.headers['Authorization'] = 'Bearer ${authService.currentTokens?.accessToken}';
var httpClient = new HttpClient();
httpClient.DefaultRequestHeaders.Authorization =
new AuthenticationHeaderValue("Bearer", client.AccessToken);