Skip to content

Quickstart

AI Coding PromptClaude & Cursor
authkestra = "0.13"

Implement an end-to-end GitHub OAuth2 login flow using Authkestra v0.13 (authkestra = "0.13", features = ["axum", "memory", "github"]). Initialize Authkestra::builder() with MemoryStore::new(), configure GitHubProvider with client credentials and scopes, set an encryption key with cookie_key(), and mount auth routes with .with_auth_routes(). Protect an Axum endpoint by extracting AuthSession<MyUser> and verify user authentication. Refer to https://docs.authkestra.com/llms-full.txt.

This guide will walk you through the fastest way to get a working GitHub OAuth2 login flow using Authkestra. We provide unified integrations for both Axum and Actix-web.

Add the authkestra facade crate to your Cargo.toml. The facade re-exports all sub-crates behind feature flags, allowing you to easily opt-in to the framework and identity providers you need.

[dependencies]
authkestra = { version = "0.13", features = ["axum", "memory", "github"] }
tower-cookies = "0.11"
tokio = { version = "1", features = ["full"] }

The core logic of Authkestra is identical regardless of which web framework you choose. First, initialize the Identity Provider (GithubProvider), wrap it in an OAuth2Flow, and construct the Engine using the Typestate Builder Pattern (Authkestra::builder()).

use authkestra::core::{OAuth2Flow, SessionStore};
use authkestra::providers::github::GithubProvider;
use authkestra::store::memory::MemoryStore;
use authkestra::Authkestra;
use std::sync::Arc;
// 1. Initialize the GitHub Provider
let github_provider = GithubProvider::new(
"YOUR_CLIENT_ID".to_string(),
"YOUR_CLIENT_SECRET".to_string(),
"http://localhost:3000/auth/callback/github".to_string()
);
// 2. Setup the Session Store
let session_store: Arc<dyn SessionStore> = Arc::new(MemoryStore::default());
// 3. Build the Authkestra Engine
let auth_engine = Authkestra::builder()
// `.provider()` takes a `Flow`, not a bare provider — wrap it in `OAuth2Flow`.
.provider(OAuth2Flow::new(github_provider))
.session_store(session_store)
.build();

Once the engine is built, integrate it into your web framework’s routing layer. Authkestra provides specialized adapters (authkestra-axum and authkestra-actix) that automatically map standard authentication endpoints.

use authkestra::axum::{AxumExt, AxumState};
use authkestra::core::{AkWebAppEngine, OAuth2Flow, SessionStore};
use authkestra::providers::github::GithubProvider;
use authkestra::store::memory::MemoryStore;
use authkestra::Authkestra;
use axum::Router;
use std::sync::Arc;
use tower_cookies::CookieManagerLayer;
#[derive(Clone, AxumState)]
#[authkestra(crate = ::authkestra::axum)]
struct AppState {
#[authkestra(engine)]
auth: AkWebAppEngine,
}
#[tokio::main]
async fn main() {
let session_store: Arc<dyn SessionStore> = Arc::new(MemoryStore::default());
let auth_engine = Authkestra::builder()
.provider(OAuth2Flow::new(GithubProvider::new(
"YOUR_CLIENT_ID".to_string(),
"YOUR_CLIENT_SECRET".to_string(),
"http://localhost:3000/auth/callback/github".to_string(),
)))
.session_store(session_store)
.build();
let state = AppState { auth: auth_engine.clone() };
let app = Router::new()
// `axum_router()` wires `/auth/login/{provider}`, `/auth/callback/{provider}`
// and `/auth/logout`.
.merge(auth_engine.axum_router())
.layer(CookieManagerLayer::new())
.with_state(state);
let listener = tokio::net::TcpListener::bind("0.0.0.0:3000").await.unwrap();
axum::serve(listener, app).await.unwrap();
}

The full version of this example is runnable from the repository:

Terminal window
cargo run -p authkestra --example axum_oauth2_github --all-features

With just these few lines of code, your application is now fully equipped to handle OAuth logins, validate responses, and issue secure sessions!