@agentxgo/oauth 0.1.0-preview.1 → 0.1.0-preview.2

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.
package/README.md CHANGED
@@ -4,7 +4,7 @@ Use AgentXGo's shared sign-in and per-connection MCP authorization in a Node.js
4
4
  application. The SDK uses ESM and requires Node.js 22.12 or later.
5
5
 
6
6
  ```sh
7
- npm install @agentxgo/oauth
7
+ npm install @agentxgo/oauth@next
8
8
  ```
9
9
 
10
10
  Pin the version approved for your application. Supply your registered issuer,
@@ -38,6 +38,23 @@ authentication. Provide a `transactions` store and a `recordLogout` handler.
38
38
  from recreating a session invalidated by the event. Return `true` when the
39
39
  event is first applied and `false` on replay.
40
40
 
41
+ ### Verified email for first sign-in
42
+
43
+ Set `requestEmail: true` in `createWebOAuth` to request `openid email`.
44
+ Persist the complete login transaction, including its optional `emailRequested`
45
+ field. Configure the issuer to include `email` and `email_verified` in the
46
+ signed ID token. `completeLogin` exposes `identity.verifiedEmail` when the
47
+ original login requested it and the issuer reports `email_verified: true`
48
+ as a boolean with a usable address. The callback still returns a signed-in
49
+ identity when the address is unavailable.
50
+
51
+ Look up the account by `(issuer, subject)` first. For a new identity, apply
52
+ your application's provisioning rules and require the verified address if your
53
+ account model needs one. Route an address that belongs to an existing account
54
+ through your account-linking flow and verify control of that account. Use
55
+ `issuedAt` as the ID token's issue time. If your application records when it
56
+ observed email verification, record that time in the provisioning transaction.
57
+
41
58
  ## MCP authorization
42
59
 
43
60
  Import `createMcpOAuth` from `@agentxgo/oauth/mcp`. Pass your issuer,
package/dist/web.d.ts CHANGED
@@ -8,6 +8,7 @@ export interface WebLoginTransaction {
8
8
  readonly verifier: string;
9
9
  readonly returnTo: string;
10
10
  readonly expiresAt: number;
11
+ readonly emailRequested?: true;
11
12
  }
12
13
  export interface WebLoginStore {
13
14
  save(binding: string, transaction: WebLoginTransaction): Awaitable<void>;
@@ -18,6 +19,7 @@ export interface WebIdentity {
18
19
  readonly subject: string;
19
20
  readonly session: string;
20
21
  readonly issuedAt: number;
22
+ readonly verifiedEmail?: string;
21
23
  }
22
24
  export interface WebLogoutEvent {
23
25
  readonly issuer: string;
@@ -33,6 +35,7 @@ export interface WebOAuthOptions {
33
35
  clientSecret?: string;
34
36
  redirectUri: string;
35
37
  postLogoutRedirectUri: string;
38
+ requestEmail?: boolean;
36
39
  transactions: WebLoginStore;
37
40
  recordLogout(event: WebLogoutEvent): Awaitable<boolean>;
38
41
  fetch?: typeof fetch;
package/dist/web.js CHANGED
@@ -23,13 +23,14 @@ async function store(operation) {
23
23
  }
24
24
  }
25
25
  export function createWebOAuth(options) {
26
- const { issuer, clientId, clientSecret, redirectUri, postLogoutRedirectUri } = options;
26
+ const { issuer, clientId, clientSecret, redirectUri, postLogoutRedirectUri, requestEmail = false, } = options;
27
27
  const callback = https(redirectUri);
28
28
  const signedOut = https(postLogoutRedirectUri);
29
29
  if (!callback ||
30
30
  !signedOut ||
31
31
  !clientIdentifier(clientId) ||
32
32
  (clientSecret !== undefined && !exactText(clientSecret, 4096)) ||
33
+ typeof requestEmail !== 'boolean' ||
33
34
  typeof options.transactions?.save !== 'function' ||
34
35
  typeof options.transactions?.take !== 'function' ||
35
36
  typeof options.recordLogout !== 'function')
@@ -51,7 +52,7 @@ export function createWebOAuth(options) {
51
52
  const expiresAt = nowSeconds() + transactionLifetime;
52
53
  const url = oidc.buildAuthorizationUrl(config, {
53
54
  redirect_uri: redirectUri,
54
- scope: 'openid',
55
+ scope: requestEmail ? 'openid email' : 'openid',
55
56
  state,
56
57
  nonce,
57
58
  code_challenge: await oidc.calculatePKCECodeChallenge(verifier),
@@ -66,6 +67,7 @@ export function createWebOAuth(options) {
66
67
  verifier,
67
68
  returnTo,
68
69
  expiresAt,
70
+ ...(requestEmail ? { emailRequested: true } : {}),
69
71
  }));
70
72
  return { authorizationUrl: url.href, binding, expiresAt };
71
73
  },
@@ -111,8 +113,21 @@ export function createWebOAuth(options) {
111
113
  !epoch(claims.iat) ||
112
114
  claims.iat > nowSeconds() + 30)
113
115
  throw new OAuthIntegrationError('invalid_login');
116
+ const verifiedEmail = requestEmail &&
117
+ flow.emailRequested === true &&
118
+ claims.email_verified === true &&
119
+ exactText(claims.email, 254) &&
120
+ /^[^\s@<>]+@[^\s@<>]+$/u.test(claims.email)
121
+ ? claims.email
122
+ : undefined;
114
123
  return {
115
- identity: { issuer, subject: claims.sub, session: claims.sid, issuedAt: claims.iat },
124
+ identity: {
125
+ issuer,
126
+ subject: claims.sub,
127
+ session: claims.sid,
128
+ issuedAt: claims.iat,
129
+ ...(verifiedEmail === undefined ? {} : { verifiedEmail }),
130
+ },
116
131
  returnTo: flow.returnTo,
117
132
  };
118
133
  },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@agentxgo/oauth",
3
- "version": "0.1.0-preview.1",
3
+ "version": "0.1.0-preview.2",
4
4
  "author": "agentxgo team",
5
5
  "description": "OAuth and OIDC integration tools for AgentXGo applications",
6
6
  "private": false,