new·The score now tells you which way it movedA brain's exam only ever grows: its own material writes questions, and so does every question a real caller asked and did not get answered. The score is a percentage over that growing set, so a brain that learned more could post a smaller number — and this week three did. One of them answered two MORE questions than the week before and showed eighteen points less. Printed as a single percentage, that reads as decline to a reader and as punishment to anyone who contributes material.all news →
mozg.beta
Sign in

Better Auth · Plugins · all subjects

generic-oauth/advanced

4 notes, read out of this brain and free to use. Each one was extracted from a source and is re-checked against its exam.

Custom token exchange example with GET request

Example of custom token exchange for non-standard endpoints: ```ts getToken: async ({ code, redirectURI }) => { const response = await fetch( `https://provider.example.com/oauth/token?` + `client_id=${process.env.CUSTOM_CLIENT_ID}&` + `client_secret=${process.env.CUSTOM_CLIENT_SECRET}&` + `code=${code}&` + `redirect_uri=${redirectURI}&` + `grant_type=authorization_code`, { method: "GET" } ); const data = await response.json(); return { accessToken: data.access_token, refreshToken: data.refresh_token, accessTokenExpiresAt: new Date(Date.now() + data.expires_in * 1000), scopes: data.scope?.split(" ") ?? [], raw: data, }; } ```

Custom getUserInfo example

Example of custom getUserInfo function with provider-specific fields: ```ts getUserInfo: async (tokens) => { const userId = tokens.raw?.user_id as string; const response = await fetch( `https://provider.example.com/api/user?` + `access_token=${tokens.accessToken}` ); const data = await response.json(); return { id: userId, name: data.display_name, email: data.email, image: data.avatar_url, emailVerified: data.email_verified, }; } ```

mapProfileToUser example

Example of mapping provider user profile fields: ```ts mapProfileToUser: async (profile) => { return { firstName: profile.given_name, // ... map other fields as needed }; } ```

Accessing raw token data in getUserInfo

The tokens parameter includes a raw field that preserves the original token response from the provider. This is useful for accessing provider-specific fields: tokens.raw?.custom_provider_field or tokens.raw?.provider_user_id.

Give your agent this brain