Skip to content

Commit 0d17ee7

Browse files
committed
chore(core): flat AuthRuntimeConfig type
1 parent d1b999e commit 0d17ee7

File tree

11 files changed

+22
-16
lines changed

11 files changed

+22
-16
lines changed

packages/core/src/@types/index.ts

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -193,27 +193,21 @@ export interface JoseInstance {
193193
decryptJWE: (payload: string) => Promise<string>
194194
}
195195

196-
/**
197-
* Internal runtime configuration used within Aura Auth after initialization.
198-
* All optional fields from AuthConfig are resolved to their default values.
199-
* @internal
200-
* @todo: is this needed?
201-
*/
202-
export interface AuthRuntimeConfig {
203-
oauth: Record<LiteralUnion<BuiltInOAuthProvider>, OAuthProviderCredentials>
204-
cookies: CookieConfig
205-
secret: string
206-
jose: JoseInstance
207-
}
208-
209196
export interface RouterGlobalContext {
210197
oauth: Record<LiteralUnion<BuiltInOAuthProvider>, OAuthProviderCredentials>
211198
cookies: CookieStoreConfig
212199
jose: JoseInstance
200+
secret?: string
213201
basePath: string
214202
trustedProxyHeaders: boolean
215203
}
216204

205+
/**
206+
* Internal runtime configuration used within Aura Auth after initialization.
207+
* All optional fields from AuthConfig are resolved to their default values.
208+
*/
209+
export type AuthRuntimeConfig = RouterGlobalContext
210+
217211
export interface AuthInstance {
218212
handlers: {
219213
GET: (request: Request) => Response | Promise<Response>

packages/core/src/actions/callback/callback.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ export const callbackAction = (oauth: AuthRuntimeConfig["oauth"]) => {
6767
}
6868

6969
const userInfo = await getUserInfo(oauthConfig, accessToken.access_token)
70-
const sessionCookie = await createSessionCookie(userInfo as JWTPayload, jose)
70+
const sessionCookie = await createSessionCookie(jose, userInfo as JWTPayload)
7171
const csrfToken = await createCSRF(jose)
7272

7373
const headers = new HeadersBuilder(cacheControl)

packages/core/src/cookie.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,10 +112,11 @@ export const getSetCookie = (response: Response, cookieName: string) => {
112112
* Create a session cookie containing a signed and encrypted JWT, using the
113113
* `@aura-stack/jose` package for the encoding.
114114
*
115+
* @param jose - Jose Instance
115116
* @param session - The JWT payload to be encoded in the session cookie
116117
* @returns The serialized session cookie string
117118
*/
118-
export const createSessionCookie = async (session: JWTPayload, jose: AuthRuntimeConfig["jose"]) => {
119+
export const createSessionCookie = async (jose: AuthRuntimeConfig["jose"], session: JWTPayload) => {
119120
try {
120121
const encoded = await jose.encodeJWT(session)
121122
return encoded

packages/core/src/index.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ const createInternalConfig = (authConfig?: AuthConfig): RouterConfig => {
2828
oauth: createBuiltInOAuthProviders(authConfig?.oauth),
2929
cookies: {} as CookieStoreConfig,
3030
jose: createJoseInstance(authConfig?.secret),
31+
secret: authConfig?.secret,
3132
basePath: authConfig?.basePath ?? "/auth",
3233
trustedProxyHeaders: !!authConfig?.trustedProxyHeaders,
3334
},

packages/core/src/oauth/discord.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,12 +49,15 @@ export interface DiscordProfile {
4949
}
5050

5151
/**
52+
* Discord OAuth Provider
53+
*
5254
* @see [Discord - Applications](https://discord.com/developers/applications)
5355
* @see [Discord - OAuth2](https://discord.com/developers/docs/topics/oauth2)
5456
* @see [Discord - Get Current User](https://discord.com/developers/docs/resources/user#get-current-user)
5557
* @see [Discord - User Object](https://discord.com/developers/docs/resources/user#user-object)
5658
* @see [Discord - OAuth2 Scopes](https://discord.com/developers/docs/topics/oauth2#shared-resources-oauth2-scopes)
5759
* @see [Discord - Image Formatting](https://discord.com/developers/docs/reference#image-formatting)
60+
* @see [Discord - Display Names](https://discord.com/developers/docs/change-log#display-names)
5861
*/
5962
export const discord: OAuthProviderConfig<DiscordProfile> = {
6063
id: "discord",
@@ -75,7 +78,6 @@ export const discord: OAuthProviderConfig<DiscordProfile> = {
7578
}
7679
return {
7780
sub: profile.id,
78-
// https://discord.com/developers/docs/change-log#display-names
7981
name: profile.global_name ?? profile.username,
8082
email: profile.email ?? "",
8183
image,

packages/core/src/oauth/figma.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ export interface FigmaProfile {
1111
}
1212

1313
/**
14+
* Figma OAuth Provider
1415
* @see [Figma - REST API Introduction](https://developers.figma.com/docs/rest-api/)
1516
* @see [Figma - OAuth App](https://www.figma.com/developers/apps/)
1617
* @see [Figma - Create an OAuth App](https://developers.figma.com/docs/rest-api/authentication/#create-an-oauth-app)

packages/core/src/oauth/github.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ export interface GitHubProfile {
5454

5555
/**
5656
* GitHub OAuth Provider
57+
*
5758
* @see [GitHub - Creating an OAuth App](https://docs.github.com/en/developers/apps/building-oauth-apps/creating-an-oauth-app)
5859
* @see [GitHub - Authorizing OAuth Apps](https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps)
5960
* @see [GitHub - Configure your GitHub OAuth Apps](https://github.com/settings/developers)

packages/core/src/oauth/gitlab.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,8 @@ export interface GitLabProfile {
5454
}
5555

5656
/**
57+
* GitLab OAuth Provider
58+
*
5759
* @see [GitLab - Applications](https://gitlab.com/-/user_settings/applications)
5860
* @see [GitLab - OAuth 2.0 identify provider API](https://docs.gitlab.com/api/oauth2/)
5961
* @see [GitLab - Scopes](https://docs.gitlab.com/integration/oauth_provider/#view-all-authorized-applications)

packages/core/src/oauth/spotify.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ export interface SpotifyProfile {
2828
}
2929

3030
/**
31+
* Spotify OAuth Provider
32+
*
3133
* @see [Spotify - Spotify Developer Dashboard](https://developer.spotify.com/dashboard)
3234
* @see [Spotify - Getting started with Web API](https://developer.spotify.com/documentation/web-api/tutorials/getting-started)
3335
* @see [Spotify - Get Current User's Profile](https://developer.spotify.com/documentation/web-api/reference/get-current-users-profile)

packages/core/src/oauth/strava.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,7 @@ export interface StravaProfile {
6666
}
6767

6868
/**
69+
* Strava OAuth Provider
6970
* @see [Strava - Getting Started with the Strava API](https://developers.strava.com/docs/getting-started/)
7071
* @see [Strava - My Applications](https://www.strava.com/settings/api)
7172
* @see [Strava - Authentication](https://developers.strava.com/docs/authentication/)

0 commit comments

Comments
 (0)