@rimelight/auth 0.0.3 → 0.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,7 +1,7 @@
1
1
  import { AuthAdapter, UserSessionContext } from "../types.mjs";
2
2
  import { decodeJwt } from "jose";
3
3
  //#region src/adapters/auth0.d.ts
4
- interface Auth0AdapterOptions {
4
+ export interface Auth0AdapterOptions {
5
5
  domain: string;
6
6
  audience?: string | undefined;
7
7
  clientId?: string | undefined;
@@ -14,7 +14,7 @@ interface Auth0AdapterOptions {
14
14
  loginUrl?: string | undefined;
15
15
  defaultRole?: string | undefined;
16
16
  }
17
- interface Auth0AuthorizeUrlOptions {
17
+ export interface Auth0AuthorizeUrlOptions {
18
18
  domain: string;
19
19
  clientId: string;
20
20
  redirectUri: string;
@@ -26,7 +26,7 @@ interface Auth0AuthorizeUrlOptions {
26
26
  prompt?: string | undefined;
27
27
  screenHint?: string | undefined;
28
28
  }
29
- interface Auth0TokenResponse {
29
+ export interface Auth0TokenResponse {
30
30
  access_token: string;
31
31
  id_token?: string | undefined;
32
32
  token_type: string;
@@ -34,7 +34,7 @@ interface Auth0TokenResponse {
34
34
  refresh_token?: string | undefined;
35
35
  scope?: string | undefined;
36
36
  }
37
- interface Auth0CodeExchangeOptions {
37
+ export interface Auth0CodeExchangeOptions {
38
38
  domain: string;
39
39
  clientId: string;
40
40
  clientSecret?: string | undefined;
@@ -42,7 +42,7 @@ interface Auth0CodeExchangeOptions {
42
42
  redirectUri: string;
43
43
  codeVerifier?: string | undefined;
44
44
  }
45
- interface Auth0PasswordLoginOptions {
45
+ export interface Auth0PasswordLoginOptions {
46
46
  domain: string;
47
47
  clientId: string;
48
48
  clientSecret?: string | undefined;
@@ -52,7 +52,7 @@ interface Auth0PasswordLoginOptions {
52
52
  scope?: string | undefined;
53
53
  realm?: string | undefined;
54
54
  }
55
- interface Auth0RefreshTokenOptions {
55
+ export interface Auth0RefreshTokenOptions {
56
56
  domain: string;
57
57
  clientId: string;
58
58
  clientSecret?: string | undefined;
@@ -62,7 +62,7 @@ interface Auth0RefreshTokenOptions {
62
62
  /**
63
63
  * Verifies an Auth0 RS256 JWT Access Token or ID Token against Auth0 JWKS endpoint
64
64
  */
65
- declare function verifyAuth0Jwt(token: string, options: {
65
+ export declare function verifyAuth0Jwt(token: string, options: {
66
66
  domain: string;
67
67
  audience?: string | undefined;
68
68
  issuer?: string | undefined;
@@ -70,33 +70,33 @@ declare function verifyAuth0Jwt(token: string, options: {
70
70
  /**
71
71
  * Creates a signed compact session token (HS256) for local session cookie storage
72
72
  */
73
- declare function createSessionToken(session: UserSessionContext, secret: string, expiresIn?: string | number): Promise<string>;
73
+ export declare function createSessionToken(session: UserSessionContext, secret: string, expiresIn?: string | number): Promise<string>;
74
74
  /**
75
75
  * Verifies a signed session token from a session cookie
76
76
  */
77
- declare function verifySessionToken(token: string, secret: string): Promise<UserSessionContext | null>;
77
+ export declare function verifySessionToken(token: string, secret: string): Promise<UserSessionContext | null>;
78
78
  /**
79
79
  * Generates an Auth0 OAuth2 / OIDC authorization URL
80
80
  */
81
- declare function createAuth0AuthorizeUrl(options: Auth0AuthorizeUrlOptions): string;
81
+ export declare function createAuth0AuthorizeUrl(options: Auth0AuthorizeUrlOptions): string;
82
82
  /**
83
83
  * Exchanges an authorization code for Auth0 tokens
84
84
  */
85
- declare function exchangeAuth0Code(options: Auth0CodeExchangeOptions): Promise<Auth0TokenResponse>;
85
+ export declare function exchangeAuth0Code(options: Auth0CodeExchangeOptions): Promise<Auth0TokenResponse>;
86
86
  /**
87
87
  * Authenticates directly with Auth0 using Resource Owner Password Credentials (ROPC). Used by
88
88
  * headless clients (e.g., Unreal Engine 5) to authenticate without browser redirects.
89
89
  */
90
- declare function loginWithAuth0Password(options: Auth0PasswordLoginOptions): Promise<Auth0TokenResponse>;
90
+ export declare function loginWithAuth0Password(options: Auth0PasswordLoginOptions): Promise<Auth0TokenResponse>;
91
91
  /**
92
92
  * Exchanges a refresh token for a new Auth0 access token. Ensures uninterrupted play sessions in
93
93
  * native game clients.
94
94
  */
95
- declare function refreshAuth0Token(options: Auth0RefreshTokenOptions): Promise<Auth0TokenResponse>;
95
+ export declare function refreshAuth0Token(options: Auth0RefreshTokenOptions): Promise<Auth0TokenResponse>;
96
96
  /**
97
97
  * Generates an Auth0 logout URL
98
98
  */
99
- declare function createAuth0LogoutUrl(options: {
99
+ export declare function createAuth0LogoutUrl(options: {
100
100
  domain: string;
101
101
  clientId: string;
102
102
  returnTo: string;
@@ -104,12 +104,12 @@ declare function createAuth0LogoutUrl(options: {
104
104
  /**
105
105
  * Auth0 / OIDC Auth Adapter
106
106
  */
107
- declare function auth0Auth(options: Auth0AdapterOptions): AuthAdapter;
108
- declare function mapAuth0PayloadToSession(payload: Record<string, any>, options: {
107
+ export declare function auth0Auth(options: Auth0AdapterOptions): AuthAdapter;
108
+ export declare function mapAuth0PayloadToSession(payload: Record<string, any>, options: {
109
109
  rolesClaim: string;
110
110
  userTypeClaim: string;
111
111
  permissionsClaim: string;
112
112
  defaultRole: string;
113
113
  }): UserSessionContext;
114
114
  //#endregion
115
- export { Auth0AdapterOptions, Auth0AuthorizeUrlOptions, Auth0CodeExchangeOptions, Auth0PasswordLoginOptions, Auth0RefreshTokenOptions, Auth0TokenResponse, auth0Auth, createAuth0AuthorizeUrl, createAuth0LogoutUrl, createSessionToken, decodeJwt, exchangeAuth0Code, loginWithAuth0Password, mapAuth0PayloadToSession, refreshAuth0Token, verifyAuth0Jwt, verifySessionToken };
115
+ export { decodeJwt };
@@ -74,8 +74,8 @@ async function exchangeAuth0Code(options) {
74
74
  code: options.code,
75
75
  redirect_uri: options.redirectUri
76
76
  };
77
- if (options.clientSecret) body.client_secret = options.clientSecret;
78
- if (options.codeVerifier) body.code_verifier = options.codeVerifier;
77
+ if (options.clientSecret) body["client_secret"] = options.clientSecret;
78
+ if (options.codeVerifier) body["code_verifier"] = options.codeVerifier;
79
79
  const response = await fetch(tokenUrl, {
80
80
  method: "POST",
81
81
  headers: { "Content-Type": "application/json" },
@@ -100,9 +100,9 @@ async function loginWithAuth0Password(options) {
100
100
  password: options.password,
101
101
  scope: options.scope || "openid profile email offline_access"
102
102
  };
103
- if (options.realm) body.realm = options.realm;
104
- if (options.clientSecret) body.client_secret = options.clientSecret;
105
- if (options.audience) body.audience = options.audience;
103
+ if (options.realm) body["realm"] = options.realm;
104
+ if (options.clientSecret) body["client_secret"] = options.clientSecret;
105
+ if (options.audience) body["audience"] = options.audience;
106
106
  const response = await fetch(tokenUrl, {
107
107
  method: "POST",
108
108
  headers: { "Content-Type": "application/json" },
@@ -125,8 +125,8 @@ async function refreshAuth0Token(options) {
125
125
  client_id: options.clientId,
126
126
  refresh_token: options.refreshToken
127
127
  };
128
- if (options.clientSecret) body.client_secret = options.clientSecret;
129
- if (options.scope) body.scope = options.scope;
128
+ if (options.clientSecret) body["client_secret"] = options.clientSecret;
129
+ if (options.scope) body["scope"] = options.scope;
130
130
  const response = await fetch(tokenUrl, {
131
131
  method: "POST",
132
132
  headers: { "Content-Type": "application/json" },
@@ -231,8 +231,8 @@ function auth0Auth(options) {
231
231
  };
232
232
  }
233
233
  function mapAuth0PayloadToSession(payload, options) {
234
- const roles = Array.isArray(payload[options.rolesClaim]) ? payload[options.rolesClaim] : Array.isArray(payload.roles) ? payload.roles : [options.defaultRole];
235
- const permissions = Array.isArray(payload[options.permissionsClaim]) ? payload[options.permissionsClaim] : Array.isArray(payload.permissions) ? payload.permissions : [];
234
+ const roles = Array.isArray(payload[options.rolesClaim]) ? payload[options.rolesClaim] : Array.isArray(payload["roles"]) ? payload["roles"] : [options.defaultRole];
235
+ const permissions = Array.isArray(payload[options.permissionsClaim]) ? payload[options.permissionsClaim] : Array.isArray(payload["permissions"]) ? payload["permissions"] : [];
236
236
  const isStaff = roles.some((r) => [
237
237
  "owner",
238
238
  "admin",
@@ -240,12 +240,12 @@ function mapAuth0PayloadToSession(payload, options) {
240
240
  "employee",
241
241
  "superadmin"
242
242
  ].includes(r.toLowerCase()));
243
- const userType = payload[options.userTypeClaim] || payload.user_type || (isStaff ? "employee" : "user");
243
+ const userType = payload[options.userTypeClaim] || payload["user_type"] || (isStaff ? "employee" : "user");
244
244
  return {
245
- userId: payload.sub || "anonymous",
246
- email: payload.email,
247
- name: payload.name || payload.nickname || payload.email?.split("@")[0] || "User",
248
- avatar: payload.picture,
245
+ userId: payload["sub"] || "anonymous",
246
+ email: payload["email"],
247
+ name: payload["name"] || payload["nickname"] || payload["email"]?.split("@")[0] || "User",
248
+ avatar: payload["picture"],
249
249
  roles,
250
250
  permissions,
251
251
  userType,
@@ -1,6 +1,6 @@
1
1
  import { AuthAdapter } from "../types.mjs";
2
2
  //#region src/adapters/cf-access.d.ts
3
- interface CfAccessAdapterOptions {
3
+ export interface CfAccessAdapterOptions {
4
4
  aud?: string | undefined;
5
5
  teamDomain?: string | undefined;
6
6
  defaultRole?: string | undefined;
@@ -8,6 +8,5 @@ interface CfAccessAdapterOptions {
8
8
  verifyJwt?: boolean | undefined;
9
9
  loginUrl?: string | undefined;
10
10
  }
11
- declare function cfAccessAuth(options?: CfAccessAdapterOptions): AuthAdapter;
12
- //#endregion
13
- export { CfAccessAdapterOptions, cfAccessAuth };
11
+ export declare function cfAccessAuth(options?: CfAccessAdapterOptions): AuthAdapter;
12
+ //#endregion
@@ -22,8 +22,8 @@ function cfAccessAuth(options = {}) {
22
22
  if (aud) verifyOpts.audience = aud;
23
23
  if (teamDomain) verifyOpts.issuer = `https://${teamDomain.replace(/^https?:\/\//, "")}`;
24
24
  const { payload } = await jwtVerify(jwtAssertion, jwks, verifyOpts);
25
- if (payload.email && typeof payload.email === "string") email = payload.email.toLowerCase().trim();
26
- if (payload.name && typeof payload.name === "string") name = payload.name;
25
+ if (payload["email"] && typeof payload["email"] === "string") email = payload["email"].toLowerCase().trim();
26
+ if (payload["name"] && typeof payload["name"] === "string") name = payload["name"];
27
27
  customClaims = payload;
28
28
  } catch {
29
29
  return null;
@@ -1,9 +1,8 @@
1
1
  import { AuthAdapter, UserSessionContext } from "../types.mjs";
2
2
  //#region src/adapters/mock.d.ts
3
- interface MockAuthOptions {
3
+ export interface MockAuthOptions {
4
4
  session?: Partial<UserSessionContext> | null;
5
5
  unauthorizedResponse?: Response;
6
6
  }
7
- declare function mockAuth(options?: MockAuthOptions | Partial<UserSessionContext>): AuthAdapter;
8
- //#endregion
9
- export { MockAuthOptions, mockAuth };
7
+ export declare function mockAuth(options?: MockAuthOptions | Partial<UserSessionContext>): AuthAdapter;
8
+ //#endregion
package/dist/index.mjs CHANGED
@@ -1,7 +1,7 @@
1
- import "./types.mjs";
2
- import { cfAccessAuth } from "./adapters/cf-access.mjs";
3
1
  import { auth0Auth, createAuth0AuthorizeUrl, createAuth0LogoutUrl, createSessionToken, decodeJwt, exchangeAuth0Code, loginWithAuth0Password, mapAuth0PayloadToSession, refreshAuth0Token, verifyAuth0Jwt, verifySessionToken } from "./adapters/auth0.mjs";
2
+ import { cfAccessAuth } from "./adapters/cf-access.mjs";
4
3
  import { mockAuth } from "./adapters/mock.mjs";
4
+ import "./types.mjs";
5
5
  import { AccessControl, adminAc, createAccessControl, createPermissions, defaultStatements, evaluateAccess, hasPermission, hasRole, memberAc, ownerAc } from "./permissions/index.mjs";
6
6
  import { RESTRICTED_SET, STANDARD_RESTRICTED_GROUPS, createRestrictedUsernameSet, normalizeUsername } from "./plugins/reserved-usernames/index.mjs";
7
7
  import { CONSTRUCTION_GUEST_COOKIE, isConstructionGuest, signInConstructionGuest } from "./plugins/construction-guest/index.mjs";
@@ -1,41 +1,41 @@
1
1
  import { UserSessionContext } from "../types.mjs";
2
2
  //#region src/permissions/index.d.ts
3
- declare function hasRole(session: UserSessionContext | null | undefined, requiredRoles: string | string[]): boolean;
4
- declare function hasPermission(session: UserSessionContext | null | undefined, requiredPermission: string): boolean;
5
- declare function evaluateAccess(session: UserSessionContext | null | undefined, constraints: {
3
+ export declare function hasRole(session: UserSessionContext | null | undefined, requiredRoles: string | string[]): boolean;
4
+ export declare function hasPermission(session: UserSessionContext | null | undefined, requiredPermission: string): boolean;
5
+ export declare function evaluateAccess(session: UserSessionContext | null | undefined, constraints: {
6
6
  roles?: string[];
7
7
  permission?: string;
8
8
  }): boolean;
9
- type StatementMap = Record<string, readonly string[]>;
10
- interface AccessRole<TStatements extends StatementMap> {
9
+ export type StatementMap = Record<string, readonly string[]>;
10
+ export interface AccessRole<TStatements extends StatementMap> {
11
11
  statements: Partial<{ [K in keyof TStatements]: TStatements[K][number][]; }>;
12
12
  can(statement: string, action: string): boolean;
13
13
  }
14
- declare class AccessControl<TStatements extends StatementMap> {
14
+ export declare class AccessControl<TStatements extends StatementMap> {
15
15
  readonly statements: TStatements;
16
16
  constructor(statements: TStatements);
17
17
  newRole(permissions: Partial<{ [K in keyof TStatements]: TStatements[K][number][]; }>): AccessRole<TStatements>;
18
18
  }
19
- declare function createAccessControl<const TStatements extends StatementMap>(statements: TStatements): AccessControl<TStatements>;
20
- declare const defaultStatements: {
19
+ export declare function createAccessControl<const TStatements extends StatementMap>(statements: TStatements): AccessControl<TStatements>;
20
+ export declare const defaultStatements: {
21
21
  user: readonly ["create", "list", "set-role", "ban", "impersonate", "delete", "setRole"];
22
22
  };
23
- declare const ownerAc: {
23
+ export declare const ownerAc: {
24
24
  statements: {
25
25
  user: string[];
26
26
  };
27
27
  };
28
- declare const adminAc: {
28
+ export declare const adminAc: {
29
29
  statements: {
30
30
  user: string[];
31
31
  };
32
32
  };
33
- declare const memberAc: {
33
+ export declare const memberAc: {
34
34
  statements: {
35
35
  user: string[];
36
36
  };
37
37
  };
38
- declare function createPermissions<const TStatements extends StatementMap>(statements: TStatements): {
38
+ export declare function createPermissions<const TStatements extends StatementMap>(statements: TStatements): {
39
39
  ac: AccessControl<{
40
40
  user: readonly ["create", "list", "set-role", "ban", "impersonate", "delete", "setRole"];
41
41
  } & TStatements>;
@@ -43,5 +43,4 @@ declare function createPermissions<const TStatements extends StatementMap>(state
43
43
  user: readonly ["create", "list", "set-role", "ban", "impersonate", "delete", "setRole"];
44
44
  } & TStatements;
45
45
  };
46
- //#endregion
47
- export { AccessControl, AccessRole, StatementMap, adminAc, createAccessControl, createPermissions, defaultStatements, evaluateAccess, hasPermission, hasRole, memberAc, ownerAc };
46
+ //#endregion
@@ -1,9 +1,8 @@
1
1
  //#region src/plugins/construction-guest/index.d.ts
2
- declare const CONSTRUCTION_GUEST_COOKIE = "rimelight-construction-guest";
3
- type GuestEnv = {
2
+ export declare const CONSTRUCTION_GUEST_COOKIE = "rimelight-construction-guest";
3
+ export type GuestEnv = {
4
4
  CONSTRUCTION_PASSPHRASE?: string;
5
5
  };
6
- declare const isConstructionGuest: (c: any) => Promise<boolean>;
7
- declare const signInConstructionGuest: (c: any, passphrase: string, rememberMe?: boolean) => Promise<boolean>;
8
- //#endregion
9
- export { CONSTRUCTION_GUEST_COOKIE, GuestEnv, isConstructionGuest, signInConstructionGuest };
6
+ export declare const isConstructionGuest: (c: any) => Promise<boolean>;
7
+ export declare const signInConstructionGuest: (c: any, passphrase: string, rememberMe?: boolean) => Promise<boolean>;
8
+ //#endregion
@@ -2,7 +2,7 @@ import { getCookie, setCookie } from "hono/cookie";
2
2
  //#region src/plugins/construction-guest/index.ts
3
3
  const CONSTRUCTION_GUEST_COOKIE = "rimelight-construction-guest";
4
4
  const getConfig = (env) => {
5
- return { passphrase: env?.CONSTRUCTION_PASSPHRASE ?? process.env.CONSTRUCTION_PASSPHRASE };
5
+ return { passphrase: env?.CONSTRUCTION_PASSPHRASE ?? process.env["CONSTRUCTION_PASSPHRASE"] };
6
6
  };
7
7
  const encode = (value) => btoa(String.fromCharCode(...value)).replace(/\+/g, "-").replace(/\//g, "_").replace(/=+$/, "");
8
8
  const decode = (value) => {
@@ -1,12 +1,11 @@
1
1
  //#region src/plugins/reserved-usernames/index.d.ts
2
- declare const normalizeUsername: (input: string) => string;
3
- declare const STANDARD_RESTRICTED_GROUPS: {
2
+ export declare const normalizeUsername: (input: string) => string;
3
+ export declare const STANDARD_RESTRICTED_GROUPS: {
4
4
  STAFF_ROLES: string[];
5
5
  LEGAL_FINANCIAL: string[];
6
6
  TECHNICAL: string[];
7
7
  LEETSPEAK: string[];
8
8
  };
9
- declare const createRestrictedUsernameSet: (customBlacklist?: string[]) => Set<string>;
10
- declare const RESTRICTED_SET: Set<string>;
11
- //#endregion
12
- export { RESTRICTED_SET, STANDARD_RESTRICTED_GROUPS, createRestrictedUsernameSet, normalizeUsername };
9
+ export declare const createRestrictedUsernameSet: (customBlacklist?: string[]) => Set<string>;
10
+ export declare const RESTRICTED_SET: Set<string>;
11
+ //#endregion
package/dist/types.d.mts CHANGED
@@ -1,6 +1,6 @@
1
1
  //#region src/types.d.ts
2
- type UserType = "user" | "employee" | "guest" | (string & {});
3
- interface UserSessionContext {
2
+ export type UserType = "user" | "employee" | "guest" | (string & {});
3
+ export interface UserSessionContext {
4
4
  /**
5
5
  * Unique user identifier (e.g. Auth0 sub claim, user UUID, or email)
6
6
  */
@@ -35,7 +35,7 @@ interface UserSessionContext {
35
35
  */
36
36
  metadata?: Record<string, any> | undefined;
37
37
  }
38
- interface AuthAdapter {
38
+ export interface AuthAdapter {
39
39
  /**
40
40
  * Unique name of the auth adapter
41
41
  */
@@ -54,5 +54,4 @@ interface AuthAdapter {
54
54
  */
55
55
  handleUnauthorized?: ((request: Request) => Response | Promise<Response>) | undefined;
56
56
  }
57
- //#endregion
58
- export { AuthAdapter, UserSessionContext, UserType };
57
+ //#endregion
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@rimelight/auth",
3
- "version": "0.0.3",
3
+ "version": "0.0.5",
4
4
  "private": false,
5
5
  "description": "Rimelight Entertainment's Universal Authentication & Identity Package",
6
6
  "homepage": "https://rimelight.com/docs",
@@ -58,11 +58,11 @@
58
58
  },
59
59
  "dependencies": {
60
60
  "drizzle-orm": "0.45.2",
61
- "jose": "6.2.11"
61
+ "jose": "6.2.12"
62
62
  },
63
63
  "devDependencies": {
64
- "@rimelight/config": "0.0.4",
65
- "@types/node": "26.4.1"
64
+ "@rimelight/config": "0.0.8",
65
+ "@types/node": "26.5.1"
66
66
  },
67
67
  "peerDependencies": {
68
68
  "drizzle-orm": ">=0.30.0",
@@ -77,7 +77,7 @@
77
77
  }
78
78
  },
79
79
  "engines": {
80
- "node": ">=26.7.0"
80
+ "node": ">=26.8.2"
81
81
  },
82
82
  "scripts": {
83
83
  "build": "vp pack",