Auth.OAuth
Auth
Authorization Code + PKCE OAuth client.
Pass provider URLs explicitly (Google, GitHub, …). The app stores state (and usually the PKCE verifier) between redirect and callback — for example in Auth.Session or Cache.
Types
Provider
type alias Provider =
{ clientId : String
, clientSecret : String
, authorizeUrl : String
, tokenUrl : String
, redirectUri : String
, scopes : List String
}OAuth client settings for one provider.
Examples
provider =
{ clientId = "…"
, clientSecret = "…"
, authorizeUrl = "https://accounts.google.com/o/oauth2/v2/auth"
, tokenUrl = "https://oauth2.googleapis.com/token"
, redirectUri = "https://app.example/oauth/callback"
, scopes = [ "openid", "email" ]
}Tokens
type alias Tokens =
{ accessToken : String
, refreshToken : Maybe String
, idToken : Maybe String
, tokenType : String
, expiresIn : Maybe Int
, raw : Value
}Token endpoint response (plus raw JSON).
Examples
tokens.accessTokenPkce
type alias Pkce =
{ verifier : String
, challenge : String
}PKCE verifier and S256 challenge.
Examples
{ verifier, challenge } = Auth.OAuth.pkceError
type Error
= Http Req.Error
| BadStatus Int String
| BadBody StringWhy authorize URL building or token exchange failed.
Examples
Err (Auth.OAuth.BadBody "missing access_token")Values
pkce
pkce : PkceMint a PKCE verifier and S256 code_challenge.
Examples
Auth.OAuth.pkceauthorizeRedirect
authorizeRedirect : Provider -> { state : String , challenge : String } -> StringBuild the provider authorize redirect URL (response_type=code, S256).
Examples
Auth.OAuth.authorizeRedirect provider
{ state = state, challenge = pkce.challenge }exchange
exchange : Provider -> { code : String , verifier : String } -> Result Error TokensExchange an authorization code + PKCE verifier for tokens.
Examples
Auth.OAuth.exchange provider { code = code, verifier = pkce.verifier }refresh
refresh : Provider -> String -> Result Error TokensRefresh an access token.
Examples
Auth.OAuth.refresh provider refreshTokenerrorToString
errorToString : Error -> StringHuman-readable form of an Error for logs.
Examples
Auth.OAuth.errorToString err