Skip to content
@deckyard/oauthext

oauthext cheatsheet

Every export of @deckyard/oauthext. The guides are listed in the introduction.

jennifer
import "oauth.j" as oauth;
import "@deckyard/oauthext/" as oauthext;

The presets return the bundled module's oauth.Config, and the logins its oauth.Token; use them with oauth.deviceStart, oauth.refresh, oauth.isExpired, oauth.save and the rest. Errors about the deck's own input are kind "oauthext"; a refusal from the token endpoint stays an oauth.OAuthError (kind "oauth", with the provider's errorCode, description and status). An unreachable endpoint is http's net.NetError (kind "net"), and a key file or reply past json's decoding caps kind "limit".

Presets

FunctionReturnsDoes
oauthext.google(clientId as string, clientSecret as string, scope as string)oauth.ConfigGoogle™'s token, device and authorization endpoints
oauthext.microsoft(tenant as string, clientId as string, clientSecret as string, scope as string)oauth.Configa Microsoft Entra™ ID tenant's v2.0 token, device and authorization endpoints; the tenant is common, organizations, consumers, a GUID or a domain, anything else is an error

Google service accounts

FunctionReturnsDoes
oauthext.googleServiceAccount(keyJson as string, scope as string)oauth.Tokenread the key file, sign an assertion for scope and trade it for a token (about an hour, no refresh token)
oauthext.googleServiceAccountAs(keyJson as string, scope as string, subject as string)oauth.Tokenthe same, acting for the user subject (domain-wide delegation); "" for the account itself
oauthext.serviceAccount(keyJson as string)ServiceAccountread and check a key file: type service_account, client_email, a PKCS#8 private_key, private_key_id, an https token_uri (or http on this machine)
oauthext.serviceAccountAssertion(sa as ServiceAccount, scope as string, subject as string)stringthe signed RS256 assertion: kid the key id, iss the account, aud the token endpoint, scope as a claim, one hour

Constants

ConstantValueMeaning
oauthext.GOOGLE_TOKEN_URL"https://oauth2.googleapis.com/token"Google's token endpoint
oauthext.GOOGLE_AUTHORIZE_URL"https://accounts.google.com/o/oauth2/v2/auth"Google's authorization endpoint
oauthext.GOOGLE_DEVICE_URL"https://oauth2.googleapis.com/device/code"Google's device-authorization endpoint
oauthext.SERVICE_ACCOUNT_LIFETIME3600seconds a service-account assertion is valid, Google's maximum

Types

ServiceAccount

FieldMeaning
clientEmail as stringthe account, name@project.iam.gserviceaccount.com
privateKey as stringits PKCS#8 PEM private key
privateKeyId as stringthe key's id, the assertion's kid
tokenUri as stringthe token endpoint the assertion is for
projectId as stringthe Google Cloud™ project, "" if the file names none