@moteurio/plugin-auth-microsoft 2026.10.23 → 2026.10.28

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 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,cAAc,EAAE,kBAAkB,EAAE,uBAAuB,EAAE,MAAM,2BAA2B,CAAC;AAC7G,OAAO,EASH,KAAK,iBAAiB,IAAI,aAAa,EAC1C,MAAM,sBAAsB,CAAC;AAe9B,eAAO,MAAM,QAAQ,EAAE,cAOtB,CAAC;AAEF,wBAAgB,IAAI,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAG;AAiFlD,wBAAgB,SAAS,CAAC,GAAG,EAAE,kBAAkB,GAAG,uBAAuB,CAM1E;AAED,wBAAgB,gBAAgB;;;;;;IAU/B;;;;;;;AAED,wBAA+D"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EACR,cAAc,EACd,kBAAkB,EAClB,uBAAuB,EAC1B,MAAM,2BAA2B,CAAC;AACnC,OAAO,EAUH,KAAK,iBAAiB,IAAI,aAAa,EAC1C,MAAM,sBAAsB,CAAC;AAe9B,eAAO,MAAM,QAAQ,EAAE,cAYtB,CAAC;AAEF,wBAAgB,IAAI,CAAC,IAAI,EAAE,aAAa,GAAG,IAAI,CAAG;AAsGlD,wBAAgB,SAAS,CAAC,GAAG,EAAE,kBAAkB,GAAG,uBAAuB,CAM1E;AAED,wBAAgB,gBAAgB;;;;;;IAU/B;;;;;;;AAED,wBAA+D"}
package/dist/index.js CHANGED
@@ -4,8 +4,8 @@
4
4
  * optional AUTH_MICROSOFT_TENANT (default `common`: work + personal Microsoft accounts).
5
5
  */
6
6
  import { Router } from 'express';
7
- import { beginOAuth, completeOAuth, exchangeAuthorizationCode, emailFromOidcClaims, fetchOidcUserInfo, oauthConfig, redirectAfterLogin, redirectLoginFailed } from '@moteurio/plugin-sdk';
8
- import { loginWithProvider } from '@moteurio/core/auth.js';
7
+ import { beginOAuth, completeOAuth, oauthChallenge, exchangeAuthorizationCode, emailFromOidcClaims, fetchOidcUserInfo, oauthConfig, redirectProviderSignIn, redirectLoginFailed } from '@moteurio/plugin-sdk';
8
+ import { startProviderSignIn } from '@moteurio/core/host.js';
9
9
  const PROVIDER = 'microsoft';
10
10
  const NOT_OFFERED = { error: 'Microsoft sign-in is not available on this server.' };
11
11
  function tenant() {
@@ -20,7 +20,12 @@ export const manifest = {
20
20
  description: 'Sign in with Microsoft work or school accounts',
21
21
  source: 'opensource',
22
22
  kind: 'optional',
23
- scope: 'global'
23
+ scope: 'global',
24
+ categories: ['auth'],
25
+ contributes: {
26
+ api: { mounts: ['/auth'], openApi: true },
27
+ auth: { providers: ['microsoft'] }
28
+ }
24
29
  };
25
30
  export function init(_ctx) { }
26
31
  function createMicrosoftRouter(ctx) {
@@ -31,13 +36,16 @@ function createMicrosoftRouter(ctx) {
31
36
  res.status(404).json(NOT_OFFERED);
32
37
  return;
33
38
  }
39
+ const state = beginOAuth(req, res, PROVIDER);
34
40
  const params = new URLSearchParams({
35
41
  client_id: config.clientId,
36
42
  redirect_uri: config.redirectUri,
37
43
  response_type: 'code',
38
44
  scope: 'openid profile email User.Read',
39
45
  response_mode: 'query',
40
- state: beginOAuth(req, res, PROVIDER)
46
+ state,
47
+ code_challenge: oauthChallenge(state),
48
+ code_challenge_method: 'S256'
41
49
  });
42
50
  res.redirect(`${microsoftBase()}/authorize?${params.toString()}`);
43
51
  });
@@ -54,15 +62,24 @@ function createMicrosoftRouter(ctx) {
54
62
  if (typeof code !== 'string' || !code)
55
63
  return redirectLoginFailed(res, 'failed');
56
64
  try {
57
- const tokens = await exchangeAuthorizationCode(`${microsoftBase()}/token`, config, code);
65
+ const tokens = await exchangeAuthorizationCode(`${microsoftBase()}/token`, config, code, started.verifier);
58
66
  const claims = await fetchOidcUserInfo('https://graph.microsoft.com/oidc/userinfo', tokens.access_token);
59
67
  const email = emailFromOidcClaims(claims);
60
- if (!email)
61
- return redirectLoginFailed(res, 'email');
62
68
  const sub = typeof claims.sub === 'string' ? claims.sub : '';
69
+ if (!sub)
70
+ throw new Error('Microsoft subject is required');
63
71
  const name = typeof claims.name === 'string' ? claims.name : undefined;
64
- const { token } = await loginWithProvider({ auth: { microsoftSub: sub }, email, name }, ctx.authCallbacks?.runOnboardingForNewUser);
65
- redirectAfterLogin(res, token, started.next);
72
+ const result = await startProviderSignIn({
73
+ auth: { microsoftSub: sub },
74
+ email: email ?? '',
75
+ suggestedEmail: typeof claims.email === 'string'
76
+ ? claims.email
77
+ : typeof claims.preferred_username === 'string'
78
+ ? claims.preferred_username
79
+ : undefined,
80
+ name
81
+ }, ctx.authCallbacks?.runOnboardingForNewUser, { link: started.link });
82
+ redirectProviderSignIn(req, res, result, started.next);
66
83
  }
67
84
  catch (err) {
68
85
  if (err instanceof Error && err.message === 'User is not active') {
@@ -79,7 +96,9 @@ const openapi = {
79
96
  get: {
80
97
  summary: 'Redirect to Microsoft login',
81
98
  tags: ['Auth'],
82
- parameters: [{ name: 'next', in: 'query', required: false, schema: { type: 'string' } }],
99
+ parameters: [
100
+ { name: 'next', in: 'query', required: false, schema: { type: 'string' } }
101
+ ],
83
102
  responses: { '302': { description: 'Redirect to Microsoft' } }
84
103
  }
85
104
  },
package/package.json CHANGED
@@ -1,31 +1,37 @@
1
1
  {
2
- "name": "@moteurio/plugin-auth-microsoft",
3
- "version": "2026.10.23",
4
- "type": "module",
5
- "main": "./dist/index.js",
6
- "types": "./dist/index.d.ts",
7
- "exports": {
8
- ".": "./dist/index.js"
9
- },
10
- "files": ["dist"],
11
- "scripts": {
12
- "build": "tsc -b",
13
- "clean": "rimraf dist",
14
- "prepublishOnly": "pnpm run build",
15
- "test": "vitest run --passWithNoTests"
16
- },
17
- "dependencies": {
18
- "@moteurio/core": "^2026.10.23",
19
- "@moteurio/plugin-sdk": "^2026.10.23",
20
- "@moteurio/types": "^2026.10.23",
21
- "express": "^4.19.2",
22
- "openapi-types": "^12.1.3"
23
- },
24
- "devDependencies": {
25
- "@types/express": "^5.0.3"
26
- },
27
- "license": "MIT",
28
- "publishConfig": {
29
- "access": "public"
30
- }
31
- }
2
+ "name": "@moteurio/plugin-auth-microsoft",
3
+ "version": "2026.10.28",
4
+ "type": "module",
5
+ "main": "./dist/index.js",
6
+ "types": "./dist/index.d.ts",
7
+ "exports": {
8
+ ".": "./dist/index.js"
9
+ },
10
+ "files": [
11
+ "dist"
12
+ ],
13
+ "dependencies": {
14
+ "express": "^4.19.2",
15
+ "openapi-types": "^12.1.3"
16
+ },
17
+ "peerDependencies": {
18
+ "@moteurio/core": "^2026.10.28",
19
+ "@moteurio/plugin-sdk": "^2026.10.28",
20
+ "@moteurio/types": "^2026.10.28"
21
+ },
22
+ "devDependencies": {
23
+ "@moteurio/core": "^2026.10.28",
24
+ "@moteurio/plugin-sdk": "^2026.10.28",
25
+ "@moteurio/types": "^2026.10.28",
26
+ "@types/express": "^5.0.3"
27
+ },
28
+ "license": "MIT",
29
+ "publishConfig": {
30
+ "access": "public"
31
+ },
32
+ "scripts": {
33
+ "build": "tsc -b",
34
+ "clean": "rimraf dist",
35
+ "test": "vitest run --passWithNoTests"
36
+ }
37
+ }