oauth2

Generated by tinox doc

tinox.core.oauth2, split out of the bundled stdlib as a standalone tinox-central package.

ModuleVersionGroup
crypto (no local docs)1.1.3tinox.core
http (no local docs)1.3.2tinox.core
json (no local docs)1.1.4tinox.core

Authorization code pkce

import tinox.core.oauth2

class Main
{
    fnc main() -> Int32
    {
        const client: OAuth2Client = OAuth2Client::new(
            "https://accounts.google.com/o/oauth2/v2/auth",
            "https://oauth2.googleapis.com/token",
            "my-client-id",
            "my-client-secret",
            "https://myapp.example.com/callback"
        )

        // Step 1: redirect the user-agent to req.url, store req.state +
        // req.codeVerifier in the session (needed again at the callback).
        const req: OAuth2AuthorizeRequest = client.buildAuthorizeUrl("openid email")
        println("redirect user to: " + req.url)

        // Step 2: in the callback handler, after checking req.state against
        // the callback's "state" query param:
        const tokens: OAuth2TokenResponse = client.exchangeCode("the-code-from-callback", req.codeVerifier)
        if (tokens.ok)
        {
            println("access token: " + tokens.accessToken)
        }
        else
        {
            println("login failed: " + tokens.errorMessage)
        }
        return 0
    }
}

class OAuth2AuthorizeRequest

Fields

urlString
stateString
codeVerifierString

class OAuth2Client

Fields

authorizeUrlString
tokenUrlString
clientIdString
clientSecretString
redirectUriString

Methods

fn new(authorizeUrl: String, tokenUrl: String, clientId: String, clientSecret: String, redirectUri: String) → OAuth2Client
fn buildAuthorizeUrl(scope: String) → OAuth2AuthorizeRequest
fn exchangeCode(code: String, codeVerifier: String) → OAuth2TokenResponse
fn refresh(refreshToken: String) → OAuth2TokenResponse
fn postToken(url: String, body: String) → OAuth2TokenResponse

class OAuth2TokenResponse

Fields

accessTokenString
refreshTokenString
tokenTypeString
expiresInInt64
idTokenString
okBool
errorMessageString