@chipmobilesdk/rn-auth 0.3.0 → 0.4.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 +239 -113
- package/README.md +221 -190
- package/package.json +72 -54
- package/skills/sdk-rn-auth/SKILL.md +65 -63
- package/src/access/accessTier.ts +88 -88
- package/src/app-auth.ts +6 -0
- package/src/config/types.ts +154 -154
- package/src/config/validateConfig.ts +114 -108
- package/src/core/authMachine.ts +380 -364
- package/src/core/profile.ts +57 -60
- package/src/core/session.ts +105 -112
- package/src/diagnostics/errors.ts +99 -85
- package/src/diagnostics/messageKeys.ts +72 -61
- package/src/index.ts +72 -83
- package/src/keychain.ts +6 -0
- package/src/oidc/authClient.ts +236 -199
- package/src/oidc/classifyError.ts +76 -76
- package/src/oidc/socialRouting.ts +66 -73
- package/src/react/AuthProvider.tsx +30 -47
- package/src/react/hooks.ts +103 -91
- package/src/testing/conformance.ts +177 -0
- package/src/testing/index.ts +30 -0
- package/src/tokens/accessToken.ts +159 -164
- package/src/tokens/secureStore.ts +85 -52
|
@@ -1,61 +1,72 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Stable, localizable message keys with English default copy (UX-006 / LIB-011).
|
|
3
|
-
* The library takes no i18n runtime dependency: consuming apps map these keys to
|
|
4
|
-
* localized strings via their own i18n system. User-actionable copy and
|
|
5
|
-
* developer/tenant-configuration copy are kept separate (UX-005).
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
'auth.action.
|
|
13
|
-
'auth.
|
|
14
|
-
'auth.
|
|
15
|
-
'auth.state.
|
|
16
|
-
'auth.state.
|
|
17
|
-
|
|
18
|
-
'auth.
|
|
19
|
-
|
|
20
|
-
'auth.tier.
|
|
21
|
-
|
|
22
|
-
'auth.
|
|
23
|
-
|
|
24
|
-
'auth.error.
|
|
25
|
-
'auth.error.
|
|
26
|
-
|
|
27
|
-
'auth.error.
|
|
28
|
-
|
|
29
|
-
'auth.error.
|
|
30
|
-
'auth.error.
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
export
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Stable, localizable message keys with English default copy (UX-006 / LIB-011).
|
|
3
|
+
* The library takes no i18n runtime dependency: consuming apps map these keys to
|
|
4
|
+
* localized strings via their own i18n system. User-actionable copy and
|
|
5
|
+
* developer/tenant-configuration copy are kept separate (UX-005).
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { defineMessages } from '@chipmobilesdk/rn-core';
|
|
9
|
+
|
|
10
|
+
export interface AuthMessageMap {
|
|
11
|
+
// User-facing actions and states
|
|
12
|
+
'auth.action.continueGoogle': string;
|
|
13
|
+
'auth.action.continueApple': string;
|
|
14
|
+
'auth.action.continueFacebook': string;
|
|
15
|
+
'auth.state.signedOut': string;
|
|
16
|
+
'auth.state.authenticating': string;
|
|
17
|
+
'auth.state.signedIn': string;
|
|
18
|
+
'auth.state.signingOut': string;
|
|
19
|
+
// Access tier (user-facing)
|
|
20
|
+
'auth.tier.free': string;
|
|
21
|
+
'auth.tier.premium': string;
|
|
22
|
+
'auth.tier.unverified': string;
|
|
23
|
+
// User-actionable errors
|
|
24
|
+
'auth.error.cancelled': string;
|
|
25
|
+
'auth.error.sessionExpired': string;
|
|
26
|
+
'auth.error.entitlement': string;
|
|
27
|
+
'auth.error.network': string;
|
|
28
|
+
// Developer / tenant-configuration errors
|
|
29
|
+
'auth.error.configuration': string;
|
|
30
|
+
'auth.error.redirectMismatch': string;
|
|
31
|
+
'auth.error.token': string;
|
|
32
|
+
'auth.error.consentDenied': string;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
export type AuthMessageKey = keyof AuthMessageMap;
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* The catalog, as an rn-core message set: `user` copy may reach an end user,
|
|
39
|
+
* `developer` copy describes a tenant or configuration fault (UX-005). Register
|
|
40
|
+
* `authMessages.user` with rn-i18n to translate it like app copy.
|
|
41
|
+
*/
|
|
42
|
+
export const authMessages = defineMessages({
|
|
43
|
+
user: {
|
|
44
|
+
'auth.action.continueGoogle': 'Continue with Google',
|
|
45
|
+
'auth.action.continueApple': 'Continue with Apple',
|
|
46
|
+
'auth.action.continueFacebook': 'Continue with Facebook',
|
|
47
|
+
'auth.state.signedOut': 'Sign in to continue',
|
|
48
|
+
'auth.state.authenticating': 'Signing you in…',
|
|
49
|
+
'auth.state.signedIn': 'You are signed in',
|
|
50
|
+
'auth.state.signingOut': 'Signing out…',
|
|
51
|
+
'auth.tier.free': 'Free',
|
|
52
|
+
'auth.tier.premium': 'Premium',
|
|
53
|
+
'auth.tier.unverified': 'Membership could not be verified',
|
|
54
|
+
'auth.error.cancelled': 'Sign-in was cancelled. You can try again.',
|
|
55
|
+
'auth.error.sessionExpired': 'Your session expired. Please sign in again.',
|
|
56
|
+
'auth.error.entitlement': 'This feature requires a verified premium membership.',
|
|
57
|
+
'auth.error.network': 'No connection. Some features are limited until you reconnect.',
|
|
58
|
+
},
|
|
59
|
+
developer: {
|
|
60
|
+
'auth.error.configuration': 'Authentication is not configured correctly.',
|
|
61
|
+
'auth.error.redirectMismatch': 'The sign-in redirect does not match the app configuration.',
|
|
62
|
+
'auth.error.token': 'We could not complete the request. Please try again.',
|
|
63
|
+
'auth.error.consentDenied': 'Access to this resource was denied.',
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
export const DEFAULT_MESSAGES: AuthMessageMap = authMessages.defaults;
|
|
68
|
+
|
|
69
|
+
/** Resolve a message, preferring app overrides over the English defaults. */
|
|
70
|
+
export function resolveMessages(overrides?: Partial<AuthMessageMap>): AuthMessageMap {
|
|
71
|
+
return authMessages.resolve(overrides);
|
|
72
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -1,83 +1,72 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* @chipmobilesdk/rn-auth — reusable Microsoft Entra External ID authentication
|
|
3
|
-
* for ChipMobileSdk-family React Native apps (public OIDC/PKCE client, no
|
|
4
|
-
* backend). This is the single public entrypoint (LIB-003); modules under
|
|
5
|
-
* `core/`, `tokens/`, `oidc/`, `access/`, and `diagnostics/` are private.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import { createAuthMachine } from './core/authMachine';
|
|
9
|
-
import type { Auth, AuthConfig, CreateAuthOptions } from './config/types';
|
|
10
|
-
|
|
11
|
-
/** Create the auth controller. Throws AuthConfigError on invalid config (FR-005). */
|
|
12
|
-
export function createAuth(config: AuthConfig, options?: CreateAuthOptions): Auth {
|
|
13
|
-
return createAuthMachine(config, options);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
// Public types
|
|
17
|
-
export type {
|
|
18
|
-
Auth,
|
|
19
|
-
AuthConfig,
|
|
20
|
-
CreateAuthOptions,
|
|
21
|
-
AuthState,
|
|
22
|
-
AuthStatus,
|
|
23
|
-
RestoreStatus,
|
|
24
|
-
Profile,
|
|
25
|
-
ProviderIdentity,
|
|
26
|
-
ProviderConfig,
|
|
27
|
-
ProviderId,
|
|
28
|
-
DevicePlatform,
|
|
29
|
-
ResourceConfig,
|
|
30
|
-
ClaimMatcher,
|
|
31
|
-
AccessTierMapping,
|
|
32
|
-
AccessTier,
|
|
33
|
-
AccessTokenResult,
|
|
34
|
-
AccessTokenStatus,
|
|
35
|
-
PremiumGateResult,
|
|
36
|
-
GlobalSignOutResult,
|
|
37
|
-
} from './config/types';
|
|
38
|
-
|
|
39
|
-
// Ports + default adapters
|
|
40
|
-
export type { SecureTokenStore } from './tokens/secureStore';
|
|
41
|
-
export { createKeychainSecureStore, AUTH_STORAGE_KEY } from './tokens/secureStore';
|
|
42
|
-
export type {
|
|
43
|
-
OidcAuthClient,
|
|
44
|
-
OidcTokens,
|
|
45
|
-
AuthorizeParams,
|
|
46
|
-
RefreshParams,
|
|
47
|
-
EndSessionParams,
|
|
48
|
-
} from './oidc/authClient';
|
|
49
|
-
export { createAppAuthClient } from './oidc/authClient';
|
|
50
|
-
|
|
51
|
-
// Access-tier evaluation (also exported for app-side reuse/testing)
|
|
52
|
-
export { evaluateAccessTier, failClosedTier } from './access/accessTier';
|
|
53
|
-
|
|
54
|
-
// Diagnostics
|
|
55
|
-
export {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
export
|
|
62
|
-
export {
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
useProfile,
|
|
74
|
-
useAccessTier,
|
|
75
|
-
useAccessToken,
|
|
76
|
-
useSignInProvider,
|
|
77
|
-
useSignInProviders,
|
|
78
|
-
} from './react/hooks';
|
|
79
|
-
export type {
|
|
80
|
-
UseAuthResult,
|
|
81
|
-
UseAccessTokenResult,
|
|
82
|
-
UseAccessTokenStatus,
|
|
83
|
-
} from './react/hooks';
|
|
1
|
+
/**
|
|
2
|
+
* @chipmobilesdk/rn-auth — reusable Microsoft Entra External ID authentication
|
|
3
|
+
* for ChipMobileSdk-family React Native apps (public OIDC/PKCE client, no
|
|
4
|
+
* backend). This is the single public entrypoint (LIB-003); modules under
|
|
5
|
+
* `core/`, `tokens/`, `oidc/`, `access/`, and `diagnostics/` are private.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { createAuthMachine } from './core/authMachine';
|
|
9
|
+
import type { Auth, AuthConfig, CreateAuthOptions } from './config/types';
|
|
10
|
+
|
|
11
|
+
/** Create the auth controller. Throws AuthConfigError on invalid config (FR-005). */
|
|
12
|
+
export function createAuth(config: AuthConfig, options?: CreateAuthOptions): Auth {
|
|
13
|
+
return createAuthMachine(config, options);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
// Public types
|
|
17
|
+
export type {
|
|
18
|
+
Auth,
|
|
19
|
+
AuthConfig,
|
|
20
|
+
CreateAuthOptions,
|
|
21
|
+
AuthState,
|
|
22
|
+
AuthStatus,
|
|
23
|
+
RestoreStatus,
|
|
24
|
+
Profile,
|
|
25
|
+
ProviderIdentity,
|
|
26
|
+
ProviderConfig,
|
|
27
|
+
ProviderId,
|
|
28
|
+
DevicePlatform,
|
|
29
|
+
ResourceConfig,
|
|
30
|
+
ClaimMatcher,
|
|
31
|
+
AccessTierMapping,
|
|
32
|
+
AccessTier,
|
|
33
|
+
AccessTokenResult,
|
|
34
|
+
AccessTokenStatus,
|
|
35
|
+
PremiumGateResult,
|
|
36
|
+
GlobalSignOutResult,
|
|
37
|
+
} from './config/types';
|
|
38
|
+
|
|
39
|
+
// Ports + default adapters
|
|
40
|
+
export type { SecureTokenStore } from './tokens/secureStore';
|
|
41
|
+
export { createKeychainSecureStore, AUTH_STORAGE_KEY } from './tokens/secureStore';
|
|
42
|
+
export type {
|
|
43
|
+
OidcAuthClient,
|
|
44
|
+
OidcTokens,
|
|
45
|
+
AuthorizeParams,
|
|
46
|
+
RefreshParams,
|
|
47
|
+
EndSessionParams,
|
|
48
|
+
} from './oidc/authClient';
|
|
49
|
+
export { createAppAuthClient } from './oidc/authClient';
|
|
50
|
+
|
|
51
|
+
// Access-tier evaluation (also exported for app-side reuse/testing)
|
|
52
|
+
export { evaluateAccessTier, failClosedTier } from './access/accessTier';
|
|
53
|
+
|
|
54
|
+
// Diagnostics
|
|
55
|
+
export { AuthError, AuthConfigError, isAuthError, redact } from './diagnostics/errors';
|
|
56
|
+
export type { AuthErrorCode, AuthErrorAudience } from './diagnostics/errors';
|
|
57
|
+
export { DEFAULT_MESSAGES, authMessages, resolveMessages } from './diagnostics/messageKeys';
|
|
58
|
+
export type { AuthMessageMap, AuthMessageKey } from './diagnostics/messageKeys';
|
|
59
|
+
|
|
60
|
+
// React bindings
|
|
61
|
+
export { AuthProvider } from './react/AuthProvider';
|
|
62
|
+
export { useAuthSelector } from './react/hooks';
|
|
63
|
+
export type { AuthProviderProps } from './react/AuthProvider';
|
|
64
|
+
export {
|
|
65
|
+
useAuth,
|
|
66
|
+
useProfile,
|
|
67
|
+
useAccessTier,
|
|
68
|
+
useAccessToken,
|
|
69
|
+
useSignInProvider,
|
|
70
|
+
useSignInProviders,
|
|
71
|
+
} from './react/hooks';
|
|
72
|
+
export type { UseAuthResult, UseAccessTokenResult, UseAccessTokenStatus } from './react/hooks';
|
package/src/keychain.ts
ADDED
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* `@chipmobilesdk/rn-auth/keychain`: the default secure token store over
|
|
3
|
+
* react-native-keychain (AUTH-09). Its own entrypoint, so an app with its own
|
|
4
|
+
* secure storage never reaches this module.
|
|
5
|
+
*/
|
|
6
|
+
export { createKeychainSecureStore, type KeychainSecureStoreOptions } from './tokens/secureStore';
|