@chipmobilesdk/rn-auth 0.4.0 → 0.6.0
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/CHANGELOG.md +139 -0
- package/README.md +74 -14
- package/lib/commonjs/access/accessTier.js +111 -0
- package/lib/commonjs/access/accessTier.js.map +1 -0
- package/lib/commonjs/app-auth.js +13 -0
- package/lib/commonjs/app-auth.js.map +1 -0
- package/lib/commonjs/config/types.js +50 -0
- package/lib/commonjs/config/types.js.map +1 -0
- package/lib/commonjs/config/validateConfig.js +114 -0
- package/lib/commonjs/config/validateConfig.js.map +1 -0
- package/lib/commonjs/core/authMachine.js +406 -0
- package/lib/commonjs/core/authMachine.js.map +1 -0
- package/lib/commonjs/core/profile.js +59 -0
- package/lib/commonjs/core/profile.js.map +1 -0
- package/lib/commonjs/core/session.js +125 -0
- package/lib/commonjs/core/session.js.map +1 -0
- package/lib/commonjs/diagnostics/errors.js +83 -0
- package/lib/commonjs/diagnostics/errors.js.map +1 -0
- package/lib/commonjs/diagnostics/messageKeys.js +51 -0
- package/lib/commonjs/diagnostics/messageKeys.js.map +1 -0
- package/lib/commonjs/index.js +175 -0
- package/lib/commonjs/index.js.map +1 -0
- package/lib/commonjs/keychain.js +13 -0
- package/lib/commonjs/keychain.js.map +1 -0
- package/lib/commonjs/oidc/authClient.js +157 -0
- package/lib/commonjs/oidc/authClient.js.map +1 -0
- package/lib/commonjs/oidc/classifyError.js +65 -0
- package/lib/commonjs/oidc/classifyError.js.map +1 -0
- package/lib/commonjs/oidc/socialRouting.js +58 -0
- package/lib/commonjs/oidc/socialRouting.js.map +1 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/commonjs/react/AuthProvider.js +37 -0
- package/lib/commonjs/react/AuthProvider.js.map +1 -0
- package/lib/commonjs/react/hooks.js +122 -0
- package/lib/commonjs/react/hooks.js.map +1 -0
- package/lib/commonjs/testing/conformance.js +148 -0
- package/lib/commonjs/testing/conformance.js.map +1 -0
- package/lib/commonjs/testing/index.js +53 -0
- package/lib/commonjs/testing/index.js.map +1 -0
- package/lib/commonjs/tokens/accessToken.js +165 -0
- package/lib/commonjs/tokens/accessToken.js.map +1 -0
- package/lib/commonjs/tokens/secureStore.js +60 -0
- package/lib/commonjs/tokens/secureStore.js.map +1 -0
- package/lib/module/access/accessTier.js +106 -0
- package/lib/module/access/accessTier.js.map +1 -0
- package/lib/module/app-auth.js +9 -0
- package/lib/module/app-auth.js.map +1 -0
- package/lib/module/config/types.js +46 -0
- package/lib/module/config/types.js.map +1 -0
- package/lib/module/config/validateConfig.js +110 -0
- package/lib/module/config/validateConfig.js.map +1 -0
- package/lib/module/core/authMachine.js +402 -0
- package/lib/module/core/authMachine.js.map +1 -0
- package/lib/module/core/profile.js +54 -0
- package/lib/module/core/profile.js.map +1 -0
- package/lib/module/core/session.js +118 -0
- package/lib/module/core/session.js.map +1 -0
- package/lib/module/diagnostics/errors.js +74 -0
- package/lib/module/diagnostics/errors.js.map +1 -0
- package/lib/module/diagnostics/messageKeys.js +46 -0
- package/lib/module/diagnostics/messageKeys.js.map +1 -0
- package/lib/module/index.js +33 -0
- package/lib/module/index.js.map +1 -0
- package/lib/module/keychain.js +9 -0
- package/lib/module/keychain.js.map +1 -0
- package/lib/module/oidc/authClient.js +152 -0
- package/lib/module/oidc/authClient.js.map +1 -0
- package/lib/module/oidc/classifyError.js +60 -0
- package/lib/module/oidc/classifyError.js.map +1 -0
- package/lib/module/oidc/socialRouting.js +52 -0
- package/lib/module/oidc/socialRouting.js.map +1 -0
- package/lib/module/package.json +1 -0
- package/lib/module/react/AuthProvider.js +31 -0
- package/lib/module/react/AuthProvider.js.map +1 -0
- package/lib/module/react/hooks.js +111 -0
- package/lib/module/react/hooks.js.map +1 -0
- package/lib/module/testing/conformance.js +140 -0
- package/lib/module/testing/conformance.js.map +1 -0
- package/lib/module/testing/index.js +25 -0
- package/lib/module/testing/index.js.map +1 -0
- package/lib/module/tokens/accessToken.js +161 -0
- package/lib/module/tokens/accessToken.js.map +1 -0
- package/lib/module/tokens/secureStore.js +56 -0
- package/lib/module/tokens/secureStore.js.map +1 -0
- package/lib/typescript/commonjs/access/accessTier.d.ts +14 -0
- package/lib/typescript/commonjs/access/accessTier.d.ts.map +1 -0
- package/lib/typescript/commonjs/app-auth.d.ts +7 -0
- package/lib/typescript/commonjs/app-auth.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/types.d.ts +171 -0
- package/lib/typescript/commonjs/config/types.d.ts.map +1 -0
- package/lib/typescript/commonjs/config/validateConfig.d.ts +8 -0
- package/lib/typescript/commonjs/config/validateConfig.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/authMachine.d.ts +14 -0
- package/lib/typescript/commonjs/core/authMachine.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/profile.d.ts +15 -0
- package/lib/typescript/commonjs/core/profile.d.ts.map +1 -0
- package/lib/typescript/commonjs/core/session.d.ts +60 -0
- package/lib/typescript/commonjs/core/session.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts +37 -0
- package/lib/typescript/commonjs/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts +57 -0
- package/lib/typescript/commonjs/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/commonjs/index.d.ts +27 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/keychain.d.ts +7 -0
- package/lib/typescript/commonjs/keychain.d.ts.map +1 -0
- package/lib/typescript/commonjs/oidc/authClient.d.ts +75 -0
- package/lib/typescript/commonjs/oidc/authClient.d.ts.map +1 -0
- package/lib/typescript/commonjs/oidc/classifyError.d.ts +28 -0
- package/lib/typescript/commonjs/oidc/classifyError.d.ts.map +1 -0
- package/lib/typescript/commonjs/oidc/socialRouting.d.ts +22 -0
- package/lib/typescript/commonjs/oidc/socialRouting.d.ts.map +1 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/commonjs/react/AuthProvider.d.ts +17 -0
- package/lib/typescript/commonjs/react/AuthProvider.d.ts.map +1 -0
- package/lib/typescript/commonjs/react/hooks.d.ts +42 -0
- package/lib/typescript/commonjs/react/hooks.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts +32 -0
- package/lib/typescript/commonjs/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/commonjs/testing/index.d.ts +11 -0
- package/lib/typescript/commonjs/testing/index.d.ts.map +1 -0
- package/lib/typescript/commonjs/tokens/accessToken.d.ts +45 -0
- package/lib/typescript/commonjs/tokens/accessToken.d.ts.map +1 -0
- package/lib/typescript/commonjs/tokens/secureStore.d.ts +26 -0
- package/lib/typescript/commonjs/tokens/secureStore.d.ts.map +1 -0
- package/lib/typescript/module/access/accessTier.d.ts +14 -0
- package/lib/typescript/module/access/accessTier.d.ts.map +1 -0
- package/lib/typescript/module/app-auth.d.ts +7 -0
- package/lib/typescript/module/app-auth.d.ts.map +1 -0
- package/lib/typescript/module/config/types.d.ts +171 -0
- package/lib/typescript/module/config/types.d.ts.map +1 -0
- package/lib/typescript/module/config/validateConfig.d.ts +8 -0
- package/lib/typescript/module/config/validateConfig.d.ts.map +1 -0
- package/lib/typescript/module/core/authMachine.d.ts +14 -0
- package/lib/typescript/module/core/authMachine.d.ts.map +1 -0
- package/lib/typescript/module/core/profile.d.ts +15 -0
- package/lib/typescript/module/core/profile.d.ts.map +1 -0
- package/lib/typescript/module/core/session.d.ts +60 -0
- package/lib/typescript/module/core/session.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/errors.d.ts +37 -0
- package/lib/typescript/module/diagnostics/errors.d.ts.map +1 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts +57 -0
- package/lib/typescript/module/diagnostics/messageKeys.d.ts.map +1 -0
- package/lib/typescript/module/index.d.ts +27 -0
- package/lib/typescript/module/index.d.ts.map +1 -0
- package/lib/typescript/module/keychain.d.ts +7 -0
- package/lib/typescript/module/keychain.d.ts.map +1 -0
- package/lib/typescript/module/oidc/authClient.d.ts +75 -0
- package/lib/typescript/module/oidc/authClient.d.ts.map +1 -0
- package/lib/typescript/module/oidc/classifyError.d.ts +28 -0
- package/lib/typescript/module/oidc/classifyError.d.ts.map +1 -0
- package/lib/typescript/module/oidc/socialRouting.d.ts +22 -0
- package/lib/typescript/module/oidc/socialRouting.d.ts.map +1 -0
- package/lib/typescript/module/package.json +1 -0
- package/lib/typescript/module/react/AuthProvider.d.ts +17 -0
- package/lib/typescript/module/react/AuthProvider.d.ts.map +1 -0
- package/lib/typescript/module/react/hooks.d.ts +42 -0
- package/lib/typescript/module/react/hooks.d.ts.map +1 -0
- package/lib/typescript/module/testing/conformance.d.ts +32 -0
- package/lib/typescript/module/testing/conformance.d.ts.map +1 -0
- package/lib/typescript/module/testing/index.d.ts +11 -0
- package/lib/typescript/module/testing/index.d.ts.map +1 -0
- package/lib/typescript/module/tokens/accessToken.d.ts +45 -0
- package/lib/typescript/module/tokens/accessToken.d.ts.map +1 -0
- package/lib/typescript/module/tokens/secureStore.d.ts +26 -0
- package/lib/typescript/module/tokens/secureStore.d.ts.map +1 -0
- package/package.json +68 -21
- package/skills/sdk-rn-auth/SKILL.md +35 -2
- package/src/config/types.ts +53 -5
- package/src/config/validateConfig.ts +32 -1
- package/src/core/authMachine.ts +40 -6
- package/src/core/profile.ts +6 -1
- package/src/core/session.ts +49 -3
- package/src/diagnostics/errors.ts +7 -5
- package/src/index.ts +7 -0
- package/src/oidc/authClient.ts +19 -1
- package/src/oidc/classifyError.ts +2 -1
- package/src/oidc/socialRouting.ts +3 -1
- package/src/react/hooks.ts +53 -14
- package/src/tokens/accessToken.ts +20 -9
|
@@ -0,0 +1,83 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.AuthError = exports.AuthConfigError = void 0;
|
|
7
|
+
exports.isAuthError = isAuthError;
|
|
8
|
+
exports.redact = redact;
|
|
9
|
+
exports.toAuthError = toAuthError;
|
|
10
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
11
|
+
/**
|
|
12
|
+
* Developer-facing diagnostics. AuthError carries a stable machine-readable
|
|
13
|
+
* code, an audience (user vs developer/tenant), and a localizable message key.
|
|
14
|
+
* `detail` is always passed through `redact` so tokens and secrets never appear
|
|
15
|
+
* in logs or error objects (FR-014).
|
|
16
|
+
*/
|
|
17
|
+
|
|
18
|
+
/** JWT-shaped values: three base64url segments separated by dots. */
|
|
19
|
+
const JWT_PATTERN = /[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}/g;
|
|
20
|
+
/** Any other long opaque token-like run; shorter than rn-core's payload run on purpose. */
|
|
21
|
+
const TOKEN_PATTERN = /[A-Za-z0-9_-]{24,}/g;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Replace token-like substrings with a placeholder so diagnostics never leak
|
|
25
|
+
* secrets or token values (FR-014): JWTs become `[redacted-token]`; URLs, e-mail
|
|
26
|
+
* addresses, UUIDs and other opaque runs become `[redacted]` (rn-core's patterns).
|
|
27
|
+
*/
|
|
28
|
+
function redact(value) {
|
|
29
|
+
if (!value) {
|
|
30
|
+
return value;
|
|
31
|
+
}
|
|
32
|
+
return (0, _rnCore.redactPatterns)(value.replace(JWT_PATTERN, '[redacted-token]'), [..._rnCore.COMMON_PATTERNS, TOKEN_PATTERN]);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** Retrying can only help when the network was the problem. */
|
|
36
|
+
const RETRYABLE = new Set(['network-unavailable']);
|
|
37
|
+
|
|
38
|
+
/** The package's error; an `SdkError` (`@chipmobilesdk/rn-core`) with `pkg: 'rn-auth'`. */
|
|
39
|
+
class AuthError extends _rnCore.SdkError {
|
|
40
|
+
constructor(args) {
|
|
41
|
+
const detail = redact(args.detail);
|
|
42
|
+
super('rn-auth', args.code, {
|
|
43
|
+
message: args.messageKey,
|
|
44
|
+
retryable: RETRYABLE.has(args.code),
|
|
45
|
+
redactedCause: detail
|
|
46
|
+
});
|
|
47
|
+
this.name = 'AuthError';
|
|
48
|
+
this.audience = args.audience ?? 'developer';
|
|
49
|
+
this.messageKey = args.messageKey;
|
|
50
|
+
this.detail = detail;
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
exports.AuthError = AuthError;
|
|
54
|
+
class AuthConfigError extends AuthError {
|
|
55
|
+
constructor(messageKey, detail) {
|
|
56
|
+
super({
|
|
57
|
+
code: 'configuration-error',
|
|
58
|
+
messageKey,
|
|
59
|
+
audience: 'developer',
|
|
60
|
+
detail
|
|
61
|
+
});
|
|
62
|
+
this.name = 'AuthConfigError';
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
exports.AuthConfigError = AuthConfigError;
|
|
66
|
+
function isAuthError(value) {
|
|
67
|
+
return value instanceof AuthError;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/** Normalize any thrown value into an AuthError without leaking secrets. */
|
|
71
|
+
function toAuthError(value, fallbackCode = 'token-acquisition-failed', fallbackMessageKey = 'auth.error.token') {
|
|
72
|
+
if (isAuthError(value)) {
|
|
73
|
+
return value;
|
|
74
|
+
}
|
|
75
|
+
const message = value instanceof Error ? value.message : String(value);
|
|
76
|
+
return new AuthError({
|
|
77
|
+
code: fallbackCode,
|
|
78
|
+
messageKey: fallbackMessageKey,
|
|
79
|
+
audience: 'developer',
|
|
80
|
+
detail: message
|
|
81
|
+
});
|
|
82
|
+
}
|
|
83
|
+
//# sourceMappingURL=errors.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","JWT_PATTERN","TOKEN_PATTERN","redact","value","redactPatterns","replace","COMMON_PATTERNS","RETRYABLE","Set","AuthError","SdkError","constructor","args","detail","code","message","messageKey","retryable","has","redactedCause","name","audience","exports","AuthConfigError","isAuthError","toAuthError","fallbackCode","fallbackMessageKey","Error","String"],"sourceRoot":"../../../src","sources":["diagnostics/errors.ts"],"mappings":";;;;;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;;AAyBA;AACA,MAAMC,WAAW,GAAG,0DAA0D;AAC9E;AACA,MAAMC,aAAa,GAAG,qBAAqB;;AAE3C;AACA;AACA;AACA;AACA;AACO,SAASC,MAAMA,CAACC,KAAyB,EAAsB;EACrE,IAAI,CAACA,KAAK,EAAE;IACX,OAAOA,KAAK;EACb;EACA,OAAO,IAAAC,sBAAc,EAACD,KAAK,CAACE,OAAO,CAACL,WAAW,EAAE,kBAAkB,CAAC,EAAE,CACrE,GAAGM,uBAAe,EAClBL,aAAa,CACb,CAAC;AACH;;AAEA;AACA,MAAMM,SAAqC,GAAG,IAAIC,GAAG,CAAgB,CAAC,qBAAqB,CAAC,CAAC;;AAE7F;AACO,MAAMC,SAAS,SAASC,gBAAQ,CAAgB;EAKtDC,WAAWA,CAACC,IAAmB,EAAE;IAChC,MAAMC,MAAM,GAAGX,MAAM,CAACU,IAAI,CAACC,MAAM,CAAC;IAClC,KAAK,CAAC,SAAS,EAAED,IAAI,CAACE,IAAI,EAAE;MAC3BC,OAAO,EAAEH,IAAI,CAACI,UAAU;MACxBC,SAAS,EAAEV,SAAS,CAACW,GAAG,CAACN,IAAI,CAACE,IAAI,CAAC;MACnCK,aAAa,EAAEN;IAChB,CAAC,CAAC;IACF,IAAI,CAACO,IAAI,GAAG,WAAW;IACvB,IAAI,CAACC,QAAQ,GAAGT,IAAI,CAACS,QAAQ,IAAI,WAAW;IAC5C,IAAI,CAACL,UAAU,GAAGJ,IAAI,CAACI,UAAU;IACjC,IAAI,CAACH,MAAM,GAAGA,MAAM;EACrB;AACD;AAACS,OAAA,CAAAb,SAAA,GAAAA,SAAA;AAEM,MAAMc,eAAe,SAASd,SAAS,CAAC;EAC9CE,WAAWA,CAACK,UAA0B,EAAEH,MAAe,EAAE;IACxD,KAAK,CAAC;MAAEC,IAAI,EAAE,qBAAqB;MAAEE,UAAU;MAAEK,QAAQ,EAAE,WAAW;MAAER;IAAO,CAAC,CAAC;IACjF,IAAI,CAACO,IAAI,GAAG,iBAAiB;EAC9B;AACD;AAACE,OAAA,CAAAC,eAAA,GAAAA,eAAA;AAEM,SAASC,WAAWA,CAACrB,KAAc,EAAsB;EAC/D,OAAOA,KAAK,YAAYM,SAAS;AAClC;;AAEA;AACO,SAASgB,WAAWA,CAC1BtB,KAAc,EACduB,YAA2B,GAAG,0BAA0B,EACxDC,kBAAkC,GAAG,kBAAkB,EAC3C;EACZ,IAAIH,WAAW,CAACrB,KAAK,CAAC,EAAE;IACvB,OAAOA,KAAK;EACb;EACA,MAAMY,OAAO,GAAGZ,KAAK,YAAYyB,KAAK,GAAGzB,KAAK,CAACY,OAAO,GAAGc,MAAM,CAAC1B,KAAK,CAAC;EACtE,OAAO,IAAIM,SAAS,CAAC;IACpBK,IAAI,EAAEY,YAAY;IAClBV,UAAU,EAAEW,kBAAkB;IAC9BN,QAAQ,EAAE,WAAW;IACrBR,MAAM,EAAEE;EACT,CAAC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.authMessages = exports.DEFAULT_MESSAGES = void 0;
|
|
7
|
+
exports.resolveMessages = resolveMessages;
|
|
8
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
9
|
+
/**
|
|
10
|
+
* Stable, localizable message keys with English default copy (UX-006 / LIB-011).
|
|
11
|
+
* The library takes no i18n runtime dependency: consuming apps map these keys to
|
|
12
|
+
* localized strings via their own i18n system. User-actionable copy and
|
|
13
|
+
* developer/tenant-configuration copy are kept separate (UX-005).
|
|
14
|
+
*/
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The catalog, as an rn-core message set: `user` copy may reach an end user,
|
|
18
|
+
* `developer` copy describes a tenant or configuration fault (UX-005). Register
|
|
19
|
+
* `authMessages.user` with rn-i18n to translate it like app copy.
|
|
20
|
+
*/
|
|
21
|
+
const authMessages = exports.authMessages = (0, _rnCore.defineMessages)({
|
|
22
|
+
user: {
|
|
23
|
+
'auth.action.continueGoogle': 'Continue with Google',
|
|
24
|
+
'auth.action.continueApple': 'Continue with Apple',
|
|
25
|
+
'auth.action.continueFacebook': 'Continue with Facebook',
|
|
26
|
+
'auth.state.signedOut': 'Sign in to continue',
|
|
27
|
+
'auth.state.authenticating': 'Signing you in…',
|
|
28
|
+
'auth.state.signedIn': 'You are signed in',
|
|
29
|
+
'auth.state.signingOut': 'Signing out…',
|
|
30
|
+
'auth.tier.free': 'Free',
|
|
31
|
+
'auth.tier.premium': 'Premium',
|
|
32
|
+
'auth.tier.unverified': 'Membership could not be verified',
|
|
33
|
+
'auth.error.cancelled': 'Sign-in was cancelled. You can try again.',
|
|
34
|
+
'auth.error.sessionExpired': 'Your session expired. Please sign in again.',
|
|
35
|
+
'auth.error.entitlement': 'This feature requires a verified premium membership.',
|
|
36
|
+
'auth.error.network': 'No connection. Some features are limited until you reconnect.'
|
|
37
|
+
},
|
|
38
|
+
developer: {
|
|
39
|
+
'auth.error.configuration': 'Authentication is not configured correctly.',
|
|
40
|
+
'auth.error.redirectMismatch': 'The sign-in redirect does not match the app configuration.',
|
|
41
|
+
'auth.error.token': 'We could not complete the request. Please try again.',
|
|
42
|
+
'auth.error.consentDenied': 'Access to this resource was denied.'
|
|
43
|
+
}
|
|
44
|
+
});
|
|
45
|
+
const DEFAULT_MESSAGES = exports.DEFAULT_MESSAGES = authMessages.defaults;
|
|
46
|
+
|
|
47
|
+
/** Resolve a message, preferring app overrides over the English defaults. */
|
|
48
|
+
function resolveMessages(overrides) {
|
|
49
|
+
return authMessages.resolve(overrides);
|
|
50
|
+
}
|
|
51
|
+
//# sourceMappingURL=messageKeys.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","authMessages","exports","defineMessages","user","developer","DEFAULT_MESSAGES","defaults","resolveMessages","overrides","resolve"],"sourceRoot":"../../../src","sources":["diagnostics/messageKeys.ts"],"mappings":";;;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AACA;AACA;;AA+BA;AACA;AACA;AACA;AACA;AACO,MAAMC,YAAY,GAAAC,OAAA,CAAAD,YAAA,GAAG,IAAAE,sBAAc,EAAC;EAC1CC,IAAI,EAAE;IACL,4BAA4B,EAAE,sBAAsB;IACpD,2BAA2B,EAAE,qBAAqB;IAClD,8BAA8B,EAAE,wBAAwB;IACxD,sBAAsB,EAAE,qBAAqB;IAC7C,2BAA2B,EAAE,iBAAiB;IAC9C,qBAAqB,EAAE,mBAAmB;IAC1C,uBAAuB,EAAE,cAAc;IACvC,gBAAgB,EAAE,MAAM;IACxB,mBAAmB,EAAE,SAAS;IAC9B,sBAAsB,EAAE,kCAAkC;IAC1D,sBAAsB,EAAE,2CAA2C;IACnE,2BAA2B,EAAE,6CAA6C;IAC1E,wBAAwB,EAAE,sDAAsD;IAChF,oBAAoB,EAAE;EACvB,CAAC;EACDC,SAAS,EAAE;IACV,0BAA0B,EAAE,6CAA6C;IACzE,6BAA6B,EAAE,4DAA4D;IAC3F,kBAAkB,EAAE,sDAAsD;IAC1E,0BAA0B,EAAE;EAC7B;AACD,CAAC,CAAC;AAEK,MAAMC,gBAAgC,GAAAJ,OAAA,CAAAI,gBAAA,GAAGL,YAAY,CAACM,QAAQ;;AAErE;AACO,SAASC,eAAeA,CAACC,SAAmC,EAAkB;EACpF,OAAOR,YAAY,CAACS,OAAO,CAACD,SAAS,CAAC;AACvC","ignoreList":[]}
|
|
@@ -0,0 +1,175 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "AUTH_STORAGE_KEY", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _secureStore.AUTH_STORAGE_KEY;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
Object.defineProperty(exports, "AuthConfigError", {
|
|
13
|
+
enumerable: true,
|
|
14
|
+
get: function () {
|
|
15
|
+
return _errors.AuthConfigError;
|
|
16
|
+
}
|
|
17
|
+
});
|
|
18
|
+
Object.defineProperty(exports, "AuthError", {
|
|
19
|
+
enumerable: true,
|
|
20
|
+
get: function () {
|
|
21
|
+
return _errors.AuthError;
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
Object.defineProperty(exports, "AuthProvider", {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () {
|
|
27
|
+
return _AuthProvider.AuthProvider;
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
Object.defineProperty(exports, "DEFAULT_MESSAGES", {
|
|
31
|
+
enumerable: true,
|
|
32
|
+
get: function () {
|
|
33
|
+
return _messageKeys.DEFAULT_MESSAGES;
|
|
34
|
+
}
|
|
35
|
+
});
|
|
36
|
+
Object.defineProperty(exports, "authMessages", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function () {
|
|
39
|
+
return _messageKeys.authMessages;
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
Object.defineProperty(exports, "createAppAuthClient", {
|
|
43
|
+
enumerable: true,
|
|
44
|
+
get: function () {
|
|
45
|
+
return _authClient.createAppAuthClient;
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
exports.createAuth = createAuth;
|
|
49
|
+
Object.defineProperty(exports, "createKeychainSecureStore", {
|
|
50
|
+
enumerable: true,
|
|
51
|
+
get: function () {
|
|
52
|
+
return _secureStore.createKeychainSecureStore;
|
|
53
|
+
}
|
|
54
|
+
});
|
|
55
|
+
Object.defineProperty(exports, "describeProviderIdentity", {
|
|
56
|
+
enumerable: true,
|
|
57
|
+
get: function () {
|
|
58
|
+
return _profile.describeProviderIdentity;
|
|
59
|
+
}
|
|
60
|
+
});
|
|
61
|
+
Object.defineProperty(exports, "evaluateAccessTier", {
|
|
62
|
+
enumerable: true,
|
|
63
|
+
get: function () {
|
|
64
|
+
return _accessTier.evaluateAccessTier;
|
|
65
|
+
}
|
|
66
|
+
});
|
|
67
|
+
Object.defineProperty(exports, "failClosedTier", {
|
|
68
|
+
enumerable: true,
|
|
69
|
+
get: function () {
|
|
70
|
+
return _accessTier.failClosedTier;
|
|
71
|
+
}
|
|
72
|
+
});
|
|
73
|
+
Object.defineProperty(exports, "isAuthError", {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return _errors.isAuthError;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
Object.defineProperty(exports, "mapClaimsToProfile", {
|
|
80
|
+
enumerable: true,
|
|
81
|
+
get: function () {
|
|
82
|
+
return _profile.mapClaimsToProfile;
|
|
83
|
+
}
|
|
84
|
+
});
|
|
85
|
+
Object.defineProperty(exports, "redact", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function () {
|
|
88
|
+
return _errors.redact;
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
Object.defineProperty(exports, "resolveMessages", {
|
|
92
|
+
enumerable: true,
|
|
93
|
+
get: function () {
|
|
94
|
+
return _messageKeys.resolveMessages;
|
|
95
|
+
}
|
|
96
|
+
});
|
|
97
|
+
Object.defineProperty(exports, "useAccessTier", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function () {
|
|
100
|
+
return _hooks.useAccessTier;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "useAccessToken", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function () {
|
|
106
|
+
return _hooks.useAccessToken;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "useAuth", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function () {
|
|
112
|
+
return _hooks.useAuth;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "useAuthMessages", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function () {
|
|
118
|
+
return _hooks.useAuthMessages;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
Object.defineProperty(exports, "useAuthSelector", {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return _hooks.useAuthSelector;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
Object.defineProperty(exports, "useProfile", {
|
|
128
|
+
enumerable: true,
|
|
129
|
+
get: function () {
|
|
130
|
+
return _hooks.useProfile;
|
|
131
|
+
}
|
|
132
|
+
});
|
|
133
|
+
Object.defineProperty(exports, "useSignInProvider", {
|
|
134
|
+
enumerable: true,
|
|
135
|
+
get: function () {
|
|
136
|
+
return _hooks.useSignInProvider;
|
|
137
|
+
}
|
|
138
|
+
});
|
|
139
|
+
Object.defineProperty(exports, "useSignInProviders", {
|
|
140
|
+
enumerable: true,
|
|
141
|
+
get: function () {
|
|
142
|
+
return _hooks.useSignInProviders;
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
var _authMachine = require("./core/authMachine.js");
|
|
146
|
+
var _profile = require("./core/profile.js");
|
|
147
|
+
var _secureStore = require("./tokens/secureStore.js");
|
|
148
|
+
var _authClient = require("./oidc/authClient.js");
|
|
149
|
+
var _accessTier = require("./access/accessTier.js");
|
|
150
|
+
var _errors = require("./diagnostics/errors.js");
|
|
151
|
+
var _messageKeys = require("./diagnostics/messageKeys.js");
|
|
152
|
+
var _AuthProvider = require("./react/AuthProvider.js");
|
|
153
|
+
var _hooks = require("./react/hooks.js");
|
|
154
|
+
/**
|
|
155
|
+
* @chipmobilesdk/rn-auth — reusable Microsoft Entra External ID authentication
|
|
156
|
+
* for ChipMobileSdk-family React Native apps (public OIDC/PKCE client, no
|
|
157
|
+
* backend). This is the single public entrypoint (LIB-003); modules under
|
|
158
|
+
* `core/`, `tokens/`, `oidc/`, `access/`, and `diagnostics/` are private.
|
|
159
|
+
*/
|
|
160
|
+
|
|
161
|
+
/** Create the auth controller. Throws AuthConfigError on invalid config (FR-005). */
|
|
162
|
+
function createAuth(config, options) {
|
|
163
|
+
return (0, _authMachine.createAuthMachine)(config, options);
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// Public types
|
|
167
|
+
|
|
168
|
+
// Ports + default adapters
|
|
169
|
+
|
|
170
|
+
// Access-tier evaluation (also exported for app-side reuse/testing)
|
|
171
|
+
|
|
172
|
+
// Diagnostics
|
|
173
|
+
|
|
174
|
+
// React bindings
|
|
175
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_authMachine","require","_profile","_secureStore","_authClient","_accessTier","_errors","_messageKeys","_AuthProvider","_hooks","createAuth","config","options","createAuthMachine"],"sourceRoot":"../../src","sources":["index.ts"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAOA,IAAAA,YAAA,GAAAC,OAAA;AAiCA,IAAAC,QAAA,GAAAD,OAAA;AAIA,IAAAE,YAAA,GAAAF,OAAA;AAUA,IAAAG,WAAA,GAAAH,OAAA;AAGA,IAAAI,WAAA,GAAAJ,OAAA;AAGA,IAAAK,OAAA,GAAAL,OAAA;AAEA,IAAAM,YAAA,GAAAN,OAAA;AAIA,IAAAO,aAAA,GAAAP,OAAA;AACA,IAAAQ,MAAA,GAAAR,OAAA;AAnEA;AACA;AACA;AACA;AACA;AACA;;AAKA;AACO,SAASS,UAAUA,CAACC,MAAkB,EAAEC,OAA2B,EAAQ;EACjF,OAAO,IAAAC,8BAAiB,EAACF,MAAM,EAAEC,OAAO,CAAC;AAC1C;;AAEA;;AAwBA;;AAiBA;;AAGA;;AAMA","ignoreList":[]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "createKeychainSecureStore", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function () {
|
|
9
|
+
return _secureStore.createKeychainSecureStore;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _secureStore = require("./tokens/secureStore.js");
|
|
13
|
+
//# sourceMappingURL=keychain.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_secureStore","require"],"sourceRoot":"../../src","sources":["keychain.ts"],"mappings":";;;;;;;;;;;AAKA,IAAAA,YAAA,GAAAC,OAAA","ignoreList":[]}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.createAppAuthClient = createAppAuthClient;
|
|
7
|
+
exports.decodeJwtClaims = decodeJwtClaims;
|
|
8
|
+
var _rnCore = require("@chipmobilesdk/rn-core");
|
|
9
|
+
var _errors = require("../diagnostics/errors.js");
|
|
10
|
+
var _classifyError = require("./classifyError.js");
|
|
11
|
+
/**
|
|
12
|
+
* OidcAuthClient port + default react-native-app-auth adapter (R1).
|
|
13
|
+
*
|
|
14
|
+
* The port abstracts the Authorization Code + PKCE public-client flow so the
|
|
15
|
+
* auth engine is testable without native code. The default adapter lazily
|
|
16
|
+
* requires react-native-app-auth and is validated on device.
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
/** Decode the payload segment of a JWT without any dependency (device-safe). */
|
|
20
|
+
function decodeJwtClaims(jwt) {
|
|
21
|
+
if (typeof jwt !== 'string') {
|
|
22
|
+
return {};
|
|
23
|
+
}
|
|
24
|
+
const [, payload] = jwt.split('.');
|
|
25
|
+
if (payload === undefined) {
|
|
26
|
+
return {};
|
|
27
|
+
}
|
|
28
|
+
try {
|
|
29
|
+
const json = base64UrlDecode(payload);
|
|
30
|
+
return JSON.parse(json);
|
|
31
|
+
} catch {
|
|
32
|
+
return {};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
const BASE64_CHARS = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/';
|
|
36
|
+
function base64UrlDecode(input) {
|
|
37
|
+
let base64 = input.replace(/-/g, '+').replace(/_/g, '/');
|
|
38
|
+
while (base64.length % 4 !== 0) {
|
|
39
|
+
base64 += '=';
|
|
40
|
+
}
|
|
41
|
+
let bytes = '';
|
|
42
|
+
let buffer = 0;
|
|
43
|
+
let bits = 0;
|
|
44
|
+
for (const char of base64) {
|
|
45
|
+
if (char === '=') {
|
|
46
|
+
break;
|
|
47
|
+
}
|
|
48
|
+
const index = BASE64_CHARS.indexOf(char);
|
|
49
|
+
if (index === -1) {
|
|
50
|
+
continue;
|
|
51
|
+
}
|
|
52
|
+
// Standard base64 bit assembly; bitwise ops are intentional here.
|
|
53
|
+
// eslint-disable-next-line no-bitwise
|
|
54
|
+
buffer = buffer << 6 | index;
|
|
55
|
+
bits += 6;
|
|
56
|
+
if (bits >= 8) {
|
|
57
|
+
bits -= 8;
|
|
58
|
+
// eslint-disable-next-line no-bitwise
|
|
59
|
+
bytes += String.fromCharCode(buffer >> bits & 0xff);
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
// Interpret the byte string (each char is a 0–255 byte) as UTF-8 without
|
|
63
|
+
// relying on the deprecated global `escape`.
|
|
64
|
+
try {
|
|
65
|
+
const percentEncoded = Array.from(bytes).map(char => '%' + char.charCodeAt(0).toString(16).padStart(2, '0')).join('');
|
|
66
|
+
return decodeURIComponent(percentEncoded);
|
|
67
|
+
} catch {
|
|
68
|
+
return bytes;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The endpoints discovery would have returned, when an app already knows them. */
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* Loaded on the first sign-in, refresh or sign-out, never at startup (PERF-05):
|
|
76
|
+
* creating the client, or the whole auth instance, loads no native code.
|
|
77
|
+
*/
|
|
78
|
+
const appAuthPeer = (0, _rnCore.lazyPeer)('react-native-app-auth', () => {
|
|
79
|
+
// Inside `try`, so Metro bundles an app that leaves this optional peer out.
|
|
80
|
+
try {
|
|
81
|
+
return require('react-native-app-auth');
|
|
82
|
+
} catch (cause) {
|
|
83
|
+
throw cause;
|
|
84
|
+
}
|
|
85
|
+
});
|
|
86
|
+
function appAuth() {
|
|
87
|
+
return appAuthPeer.require(peer => new _errors.AuthConfigError('auth.error.configuration', `${peer} is not installed or its native module is not linked`));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The module's calls, resolved only when one is made. */
|
|
91
|
+
const AppAuth = {
|
|
92
|
+
authorize: config => appAuth().authorize(config),
|
|
93
|
+
refresh: (config, params) => appAuth().refresh(config, params),
|
|
94
|
+
logout: (config, params) => appAuth().logout(config, params)
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Default OidcAuthClient adapter wrapping react-native-app-auth (PKCE public
|
|
99
|
+
* client). Validated on device (R8).
|
|
100
|
+
*/
|
|
101
|
+
function createAppAuthClient(options = {}) {
|
|
102
|
+
const serviceConfiguration = options.serviceConfiguration;
|
|
103
|
+
// Discovery is pointless once the endpoints are given, whatever was asked for.
|
|
104
|
+
const useDiscovery = serviceConfiguration ? false : options.useDiscovery ?? true;
|
|
105
|
+
const baseConfig = (authority, clientId, redirectUrl, scopes) => ({
|
|
106
|
+
issuer: useDiscovery ? authority : undefined,
|
|
107
|
+
...(serviceConfiguration ? {
|
|
108
|
+
serviceConfiguration
|
|
109
|
+
} : {}),
|
|
110
|
+
clientId,
|
|
111
|
+
redirectUrl,
|
|
112
|
+
scopes
|
|
113
|
+
});
|
|
114
|
+
const toTokens = result => ({
|
|
115
|
+
accessToken: result.accessToken,
|
|
116
|
+
// Absent stays absent: an empty string was indistinguishable from a real
|
|
117
|
+
// token by type, and silently disabled session persistence.
|
|
118
|
+
refreshToken: result.refreshToken || undefined,
|
|
119
|
+
idToken: result.idToken || undefined,
|
|
120
|
+
claims: decodeJwtClaims(result.idToken),
|
|
121
|
+
accessTokenExpiresAt: result.accessTokenExpirationDate ? new Date(result.accessTokenExpirationDate).getTime() : undefined
|
|
122
|
+
});
|
|
123
|
+
return {
|
|
124
|
+
async authorize(params) {
|
|
125
|
+
try {
|
|
126
|
+
const result = await AppAuth.authorize({
|
|
127
|
+
...baseConfig(params.authority, params.clientId, params.redirectUrl, params.scopes),
|
|
128
|
+
additionalParameters: params.additionalParameters
|
|
129
|
+
});
|
|
130
|
+
return toTokens(result);
|
|
131
|
+
} catch (error) {
|
|
132
|
+
throw (0, _classifyError.classifyAppAuthError)(error);
|
|
133
|
+
}
|
|
134
|
+
},
|
|
135
|
+
async refresh(params) {
|
|
136
|
+
try {
|
|
137
|
+
const result = await AppAuth.refresh(baseConfig(params.authority, params.clientId, params.redirectUrl, params.scopes), {
|
|
138
|
+
refreshToken: params.refreshToken
|
|
139
|
+
});
|
|
140
|
+
return toTokens(result);
|
|
141
|
+
} catch (error) {
|
|
142
|
+
throw (0, _classifyError.classifyAppAuthError)(error);
|
|
143
|
+
}
|
|
144
|
+
},
|
|
145
|
+
async endSession(params) {
|
|
146
|
+
try {
|
|
147
|
+
await AppAuth.logout(baseConfig(params.authority, params.clientId, params.redirectUrl, []), {
|
|
148
|
+
idToken: params.idToken ?? '',
|
|
149
|
+
postLogoutRedirectUrl: params.redirectUrl
|
|
150
|
+
});
|
|
151
|
+
} catch (error) {
|
|
152
|
+
throw (0, _classifyError.classifyAppAuthError)(error);
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
};
|
|
156
|
+
}
|
|
157
|
+
//# sourceMappingURL=authClient.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_rnCore","require","_errors","_classifyError","decodeJwtClaims","jwt","payload","split","undefined","json","base64UrlDecode","JSON","parse","BASE64_CHARS","input","base64","replace","length","bytes","buffer","bits","char","index","indexOf","String","fromCharCode","percentEncoded","Array","from","map","charCodeAt","toString","padStart","join","decodeURIComponent","appAuthPeer","lazyPeer","cause","appAuth","peer","AuthConfigError","AppAuth","authorize","config","refresh","params","logout","createAppAuthClient","options","serviceConfiguration","useDiscovery","baseConfig","authority","clientId","redirectUrl","scopes","issuer","toTokens","result","accessToken","refreshToken","idToken","claims","accessTokenExpiresAt","accessTokenExpirationDate","Date","getTime","additionalParameters","error","classifyAppAuthError","endSession","postLogoutRedirectUrl"],"sourceRoot":"../../../src","sources":["oidc/authClient.ts"],"mappings":";;;;;;;AAQA,IAAAA,OAAA,GAAAC,OAAA;AAEA,IAAAC,OAAA,GAAAD,OAAA;AAEA,IAAAE,cAAA,GAAAF,OAAA;AAZA;AACA;AACA;AACA;AACA;AACA;AACA;;AAuDA;AACO,SAASG,eAAeA,CAACC,GAA8B,EAA2B;EACxF,IAAI,OAAOA,GAAG,KAAK,QAAQ,EAAE;IAC5B,OAAO,CAAC,CAAC;EACV;EACA,MAAM,GAAGC,OAAO,CAAC,GAAGD,GAAG,CAACE,KAAK,CAAC,GAAG,CAAC;EAClC,IAAID,OAAO,KAAKE,SAAS,EAAE;IAC1B,OAAO,CAAC,CAAC;EACV;EACA,IAAI;IACH,MAAMC,IAAI,GAAGC,eAAe,CAACJ,OAAO,CAAC;IACrC,OAAOK,IAAI,CAACC,KAAK,CAACH,IAAI,CAAC;EACxB,CAAC,CAAC,MAAM;IACP,OAAO,CAAC,CAAC;EACV;AACD;AAEA,MAAMI,YAAY,GAAG,kEAAkE;AAEvF,SAASH,eAAeA,CAACI,KAAa,EAAU;EAC/C,IAAIC,MAAM,GAAGD,KAAK,CAACE,OAAO,CAA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ER,MAAM,CAACS,WAAW,EAAE,EAAE,CAAC,EACrE;UACCO,OAAO,EAAEhB,MAAM,CAACgB,OAAO,IAAI,EAAE;UAC7BU,qBAAqB,EAAE1B,MAAM,CAACS;QAC/B,CACD,CAAC;MACF,CAAC,CAAC,OAAOc,KAAK,EAAE;QACf,MAAM,IAAAC,mCAAoB,EAACD,KAAK,CAAC;MAClC;IACD;EACD,CAAC;AACF","ignoreList":[]}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.DEFAULT_CLASSIFICATION_RULES = void 0;
|
|
7
|
+
exports.classifyAppAuthError = classifyAppAuthError;
|
|
8
|
+
var _errors = require("../diagnostics/errors.js");
|
|
9
|
+
/**
|
|
10
|
+
* Classifies a native OIDC error into an `AuthErrorCode`.
|
|
11
|
+
*
|
|
12
|
+
* The rules are an ordered table rather than a chain of substring checks, so a
|
|
13
|
+
* platform adapter (the iOS one, later) adds its own rows without touching the
|
|
14
|
+
* engine. Order matters: the first matching rule wins.
|
|
15
|
+
*
|
|
16
|
+
* The default is deliberately not "session expired". Restore clears the stored
|
|
17
|
+
* session only on `session-expired`, so anything this table cannot name — a
|
|
18
|
+
* timeout, a 5xx, a discovery failure, a localized message — must keep the
|
|
19
|
+
* session rather than sign the user out.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* OAuth error codes (RFC 6749 §5.2, OIDC Core §3.1.2.6) and the Entra ID AADSTS
|
|
24
|
+
* codes that mean the same thing, plus the transport failures app-auth reports.
|
|
25
|
+
*/
|
|
26
|
+
const DEFAULT_CLASSIFICATION_RULES = exports.DEFAULT_CLASSIFICATION_RULES = [{
|
|
27
|
+
code: 'provider-cancelled',
|
|
28
|
+
messageKey: 'auth.error.cancelled',
|
|
29
|
+
pattern: /cancel|user_cancel|authorization flow (was )?dismissed/i
|
|
30
|
+
}, {
|
|
31
|
+
code: 'session-expired',
|
|
32
|
+
messageKey: 'auth.error.sessionExpired',
|
|
33
|
+
// invalid_grant is the refresh-token verdict; the AADSTS codes are Entra's
|
|
34
|
+
// expired, revoked, or inactive refresh token and password-changed cases.
|
|
35
|
+
pattern: /\binvalid_grant\b|\binteraction_required\b|\blogin_required\b|AADSTS(700082|700084|50173|70043)\b/i
|
|
36
|
+
}, {
|
|
37
|
+
code: 'redirect-mismatch',
|
|
38
|
+
messageKey: 'auth.error.redirectMismatch',
|
|
39
|
+
pattern: /redirect_uri|redirect uri|redirect_mismatch|AADSTS50011\b/i
|
|
40
|
+
}, {
|
|
41
|
+
code: 'consent-denied',
|
|
42
|
+
messageKey: 'auth.error.consentDenied',
|
|
43
|
+
pattern: /\baccess_denied\b|\bconsent_required\b|AADSTS65001\b/i
|
|
44
|
+
}, {
|
|
45
|
+
code: 'network-unavailable',
|
|
46
|
+
messageKey: 'auth.error.network',
|
|
47
|
+
pattern: /network|connection|offline|timed? ?out|unable to resolve host|unreachable|\bserver_error\b|\btemporarily_unavailable\b|\b5\d\d\b/i
|
|
48
|
+
}];
|
|
49
|
+
|
|
50
|
+
/** Maps a native app-auth error to a classified AuthError without leaking tokens. */
|
|
51
|
+
function classifyAppAuthError(error, rules = DEFAULT_CLASSIFICATION_RULES) {
|
|
52
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
53
|
+
const nativeCode = error?.code;
|
|
54
|
+
const haystack = `${typeof nativeCode === 'string' ? nativeCode : ''} ${message}`;
|
|
55
|
+
const rule = rules.find(candidate => candidate.pattern.test(haystack));
|
|
56
|
+
const code = rule?.code ?? 'token-acquisition-failed';
|
|
57
|
+
return new _errors.AuthError({
|
|
58
|
+
code,
|
|
59
|
+
messageKey: rule?.messageKey ?? 'auth.error.token',
|
|
60
|
+
audience: code === 'redirect-mismatch' ? 'developer' : 'user',
|
|
61
|
+
// AuthError redacts `detail`, so token-shaped values never survive.
|
|
62
|
+
detail: message
|
|
63
|
+
});
|
|
64
|
+
}
|
|
65
|
+
//# sourceMappingURL=classifyError.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","DEFAULT_CLASSIFICATION_RULES","exports","code","messageKey","pattern","classifyAppAuthError","error","rules","message","Error","String","nativeCode","haystack","rule","find","candidate","test","AuthError","audience","detail"],"sourceRoot":"../../../src","sources":["oidc/classifyError.ts"],"mappings":";;;;;;;AAaA,IAAAA,OAAA,GAAAC,OAAA;AAbA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;AACA;;AAYA;AACA;AACA;AACA;AACO,MAAMC,4BAA2D,GAAAC,OAAA,CAAAD,4BAAA,GAAG,CAC1E;EACCE,IAAI,EAAE,oBAAoB;EAC1BC,UAAU,EAAE,sBAAsB;EAClCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,iBAAiB;EACvBC,UAAU,EAAE,2BAA2B;EACvC;EACA;EACAC,OAAO,EACN;AACF,CAAC,EACD;EACCF,IAAI,EAAE,mBAAmB;EACzBC,UAAU,EAAE,6BAA6B;EACzCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,gBAAgB;EACtBC,UAAU,EAAE,0BAA0B;EACtCC,OAAO,EAAE;AACV,CAAC,EACD;EACCF,IAAI,EAAE,qBAAqB;EAC3BC,UAAU,EAAE,oBAAoB;EAChCC,OAAO,EACN;AACF,CAAC,CACD;;AAED;AACO,SAASC,oBAAoBA,CACnCC,KAAc,EACdC,KAAoC,GAAGP,4BAA4B,EACvD;EACZ,MAAMQ,OAAO,GAAGF,KAAK,YAAYG,KAAK,GAAGH,KAAK,CAACE,OAAO,GAAGE,MAAM,CAACJ,KAAK,CAAC;EACtE,MAAMK,UAAU,GAAIL,KAAK,EAAqCJ,IAAI;EAClE,MAAMU,QAAQ,GAAG,GAAG,OAAOD,UAAU,KAAK,QAAQ,GAAGA,UAAU,GAAG,EAAE,IAAIH,OAAO,EAAE;EACjF,MAAMK,IAAI,GAAGN,KAAK,CAACO,IAAI,CAACC,SAAS,IAAIA,SAAS,CAACX,OAAO,CAACY,IAAI,CAACJ,QAAQ,CAAC,CAAC;EACtE,MAAMV,IAAI,GAAGW,IAAI,EAAEX,IAAI,IAAI,0BAA0B;EACrD,OAAO,IAAIe,iBAAS,CAAC;IACpBf,IAAI;IACJC,UAAU,EAAEU,IAAI,EAAEV,UAAU,IAAI,kBAAkB;IAClDe,QAAQ,EAAEhB,IAAI,KAAK,mBAAmB,GAAG,WAAW,GAAG,MAAM;IAC7D;IACAiB,MAAM,EAAEX;EACT,CAAC,CAAC;AACH","ignoreList":[]}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.availableProvidersForPlatform = availableProvidersForPlatform;
|
|
7
|
+
exports.buildAdditionalParameters = buildAdditionalParameters;
|
|
8
|
+
exports.defaultProviderForPlatform = defaultProviderForPlatform;
|
|
9
|
+
exports.resolveProvider = resolveProvider;
|
|
10
|
+
var _errors = require("../diagnostics/errors.js");
|
|
11
|
+
/**
|
|
12
|
+
* Social provider routing (FR-002/FR-003, R3). Google and Apple are federated
|
|
13
|
+
* inside the External ID tenant; the app presents the platform-correct action
|
|
14
|
+
* and starts the user flow with a per-provider `domain_hint`.
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
/** Find the configured provider, ensuring it is enabled for the platform. */
|
|
18
|
+
function resolveProvider(config, providerId, platform) {
|
|
19
|
+
const provider = config.providers.find(candidate => candidate.id === providerId);
|
|
20
|
+
if (!provider) {
|
|
21
|
+
throw new _errors.AuthConfigError('auth.error.configuration', `Provider "${providerId}" is not configured`);
|
|
22
|
+
}
|
|
23
|
+
if (!provider.platforms.includes(platform)) {
|
|
24
|
+
throw new _errors.AuthConfigError('auth.error.configuration', `Provider "${providerId}" is not enabled for platform "${platform}"`);
|
|
25
|
+
}
|
|
26
|
+
if (provider.available === false) {
|
|
27
|
+
throw new _errors.AuthConfigError('auth.error.configuration', `Provider "${providerId}" is marked unavailable`);
|
|
28
|
+
}
|
|
29
|
+
return provider;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/** Build the OIDC additional parameters that route to the chosen IdP. */
|
|
33
|
+
function buildAdditionalParameters(provider) {
|
|
34
|
+
// The routing hint last: a provider's own parameters cannot redirect the flow
|
|
35
|
+
// to a different IdP than the one the user tapped.
|
|
36
|
+
return {
|
|
37
|
+
...provider.additionalParameters,
|
|
38
|
+
domain_hint: provider.domainHint
|
|
39
|
+
};
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* All providers to present on a given platform, in configuration array order
|
|
44
|
+
* (FR-003/FR-004). Filtered to providers enabled for the platform and not marked
|
|
45
|
+
* unavailable.
|
|
46
|
+
*/
|
|
47
|
+
function availableProvidersForPlatform(config, platform) {
|
|
48
|
+
return config.providers.filter(provider => provider.platforms.includes(platform) && provider.available !== false);
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/**
|
|
52
|
+
* The first available provider for a platform (UX-004, back-compat). Equals
|
|
53
|
+
* `availableProvidersForPlatform(config, platform)[0]`.
|
|
54
|
+
*/
|
|
55
|
+
function defaultProviderForPlatform(config, platform) {
|
|
56
|
+
return availableProvidersForPlatform(config, platform)[0];
|
|
57
|
+
}
|
|
58
|
+
//# sourceMappingURL=socialRouting.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"names":["_errors","require","resolveProvider","config","providerId","platform","provider","providers","find","candidate","id","AuthConfigError","platforms","includes","available","buildAdditionalParameters","additionalParameters","domain_hint","domainHint","availableProvidersForPlatform","filter","defaultProviderForPlatform"],"sourceRoot":"../../../src","sources":["oidc/socialRouting.ts"],"mappings":";;;;;;;;;AAOA,IAAAA,OAAA,GAAAC,OAAA;AAPA;AACA;AACA;AACA;AAC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