@microsoft/power-apps-native-auth 0.3.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/LICENSE +112 -0
- package/README.md +54 -0
- package/android/build.gradle +79 -0
- package/android/src/main/AndroidManifest.xml +31 -0
- package/android/src/main/java/expo/modules/msalintune/ExpoMsalIntuneModule.kt +488 -0
- package/app.plugin.js +4 -0
- package/expo-module.config.json +9 -0
- package/ios/ExpoMsalIntune.podspec +27 -0
- package/ios/ExpoMsalIntuneAppDelegate.swift +31 -0
- package/ios/ExpoMsalIntuneModule.swift +382 -0
- package/lib/NOTICE.txt +5 -0
- package/lib/commonjs/AuthConfig.types.js +1 -0
- package/lib/commonjs/ExpoMsalIntune.types.js +1 -0
- package/lib/commonjs/ExpoMsalIntuneModule.js +50 -0
- package/lib/commonjs/index.js +217 -0
- package/lib/commonjs/package.json +1 -0
- package/lib/module/AuthConfig.types.js +1 -0
- package/lib/module/ExpoMsalIntune.types.js +1 -0
- package/lib/module/ExpoMsalIntuneModule.js +44 -0
- package/lib/module/index.js +207 -0
- package/lib/module/package.json +1 -0
- package/lib/typescript/commonjs/AuthConfig.types.d.ts +76 -0
- package/lib/typescript/commonjs/ExpoMsalIntune.types.d.ts +80 -0
- package/lib/typescript/commonjs/ExpoMsalIntuneModule.d.ts +92 -0
- package/lib/typescript/commonjs/index.d.ts +125 -0
- package/lib/typescript/commonjs/package.json +1 -0
- package/lib/typescript/module/AuthConfig.types.d.ts +76 -0
- package/lib/typescript/module/ExpoMsalIntune.types.d.ts +80 -0
- package/lib/typescript/module/ExpoMsalIntuneModule.d.ts +92 -0
- package/lib/typescript/module/index.d.ts +125 -0
- package/lib/typescript/module/package.json +1 -0
- package/package.json +93 -0
- package/plugin/index.js +528 -0
- package/plugin/withMsalRedirectScheme.js +53 -0
- package/scripts/setup-android-sdk.js +122 -0
- package/scripts/setup-ios-frameworks.js +100 -0
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* power-apps-native-auth — native module bindings.
|
|
5
|
+
*
|
|
6
|
+
* This module is resolved at runtime via expo-modules-core. On iOS and
|
|
7
|
+
* Android it delegates to the native implementations; on web or in test
|
|
8
|
+
* environments it throws, which surfaces as a clear error rather than a
|
|
9
|
+
* silent no-op.
|
|
10
|
+
*/
|
|
11
|
+
|
|
12
|
+
import { requireNativeModule } from 'expo-modules-core';
|
|
13
|
+
// requireNativeModule throws if the native module is not linked — the error
|
|
14
|
+
// message is user-friendly (mentions expo-modules-core and the module name).
|
|
15
|
+
const ExpoMsalIntuneModule = requireNativeModule('ExpoMsalIntune');
|
|
16
|
+
|
|
17
|
+
// ---------------------------------------------------------------------------
|
|
18
|
+
// Helpers: map native shapes to public types
|
|
19
|
+
// ---------------------------------------------------------------------------
|
|
20
|
+
|
|
21
|
+
export function mapNativeAccount(native) {
|
|
22
|
+
let claims = {};
|
|
23
|
+
try {
|
|
24
|
+
claims = JSON.parse(native.claims);
|
|
25
|
+
} catch {
|
|
26
|
+
// leave claims empty if JSON is malformed
|
|
27
|
+
}
|
|
28
|
+
return {
|
|
29
|
+
identifier: native.identifier,
|
|
30
|
+
username: native.username,
|
|
31
|
+
tenantId: native.tenantId,
|
|
32
|
+
claims
|
|
33
|
+
};
|
|
34
|
+
}
|
|
35
|
+
export function mapNativeResult(native) {
|
|
36
|
+
return {
|
|
37
|
+
accessToken: native.accessToken,
|
|
38
|
+
idToken: native.idToken || undefined,
|
|
39
|
+
expiresOn: native.expiresOn,
|
|
40
|
+
scopes: native.scopes,
|
|
41
|
+
account: mapNativeAccount(native.account)
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
export default ExpoMsalIntuneModule;
|
|
@@ -0,0 +1,207 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* power-apps-native-auth — public API.
|
|
5
|
+
*
|
|
6
|
+
* Drop-in replacement for react-native-msal: exports a default
|
|
7
|
+
* `PublicClientApplication` class with the same interface used by
|
|
8
|
+
* power-apps-native-player/src/auth/msalAuth.native.ts, plus Intune MAM
|
|
9
|
+
* helpers for enrollment/unenrollment.
|
|
10
|
+
*
|
|
11
|
+
* Metro alias (metro.config.js):
|
|
12
|
+
* 'react-native-msal' → '@microsoft/power-apps-native-auth'
|
|
13
|
+
*
|
|
14
|
+
* This means the tarball's msalAuth.native.ts continues to work without
|
|
15
|
+
* patching.
|
|
16
|
+
*
|
|
17
|
+
*/
|
|
18
|
+
|
|
19
|
+
import ExpoMsalIntuneModule, { mapNativeAccount, mapNativeResult } from "./ExpoMsalIntuneModule.js";
|
|
20
|
+
// ---------------------------------------------------------------------------
|
|
21
|
+
// PublicClientApplication
|
|
22
|
+
// ---------------------------------------------------------------------------
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Wraps the native MSAL PublicClientApplication. Construct once, call
|
|
26
|
+
* `init()`, then reuse for the app's lifetime.
|
|
27
|
+
*
|
|
28
|
+
* API is intentionally compatible with react-native-msal v4 so that existing
|
|
29
|
+
* callers require zero changes.
|
|
30
|
+
*/
|
|
31
|
+
export class PublicClientApplication {
|
|
32
|
+
_initialized = false;
|
|
33
|
+
constructor(config) {
|
|
34
|
+
this._config = config;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** True after `init()` has completed successfully. */
|
|
38
|
+
get isInitialized() {
|
|
39
|
+
return this._initialized;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* Create the native MSAL PCA instance. Must be called before any other
|
|
44
|
+
* method.
|
|
45
|
+
*/
|
|
46
|
+
async init() {
|
|
47
|
+
const useEmbeddedWebView = this._config.androidConfigOptions?.authorization_user_agent === 'WEBVIEW';
|
|
48
|
+
await ExpoMsalIntuneModule.initializeClient(this._config.auth.clientId, this._config.auth.authority, this._config.auth.redirectUri ?? '', useEmbeddedWebView, this._config.useBroker ?? false);
|
|
49
|
+
this._initialized = true;
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Launch an interactive sign-in / consent dialog.
|
|
54
|
+
*/
|
|
55
|
+
async acquireToken(params) {
|
|
56
|
+
if (!this._initialized) {
|
|
57
|
+
throw new Error('ExpoMsalIntune: call init() before acquiring tokens');
|
|
58
|
+
}
|
|
59
|
+
const native = await ExpoMsalIntuneModule.acquireTokenInteractive(params.scopes, params.loginHint ?? null, params.prompt ?? null);
|
|
60
|
+
return mapNativeResult(native);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Silently acquire a token from the MSAL cache or broker.
|
|
65
|
+
* Falls back to interactive if the cache cannot satisfy the request — the
|
|
66
|
+
* caller should catch `MSALError.interactionRequired` and call
|
|
67
|
+
* `acquireToken` instead.
|
|
68
|
+
*/
|
|
69
|
+
async acquireTokenSilent(params) {
|
|
70
|
+
if (!this._initialized) {
|
|
71
|
+
throw new Error('ExpoMsalIntune: call init() before acquiring tokens');
|
|
72
|
+
}
|
|
73
|
+
const native = await ExpoMsalIntuneModule.acquireTokenSilent(params.scopes, params.account.identifier, params.forceRefresh ?? false);
|
|
74
|
+
return mapNativeResult(native);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/** Return all accounts from the MSAL token cache. */
|
|
78
|
+
async getAccounts() {
|
|
79
|
+
const nativeAccounts = await ExpoMsalIntuneModule.getAccounts();
|
|
80
|
+
return nativeAccounts.map(mapNativeAccount);
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Remove the account from the MSAL cache and optionally end the browser
|
|
85
|
+
* SSO session.
|
|
86
|
+
*/
|
|
87
|
+
async signOut(params) {
|
|
88
|
+
await ExpoMsalIntuneModule.signOut(params.account.identifier, params.signoutFromBrowser ?? false);
|
|
89
|
+
return true;
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
// ---------------------------------------------------------------------------
|
|
94
|
+
// Intune MAM helpers
|
|
95
|
+
// ---------------------------------------------------------------------------
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Register a signed-in account with Intune MAM and initiate device/app
|
|
99
|
+
* enrollment. Call this immediately after a successful `acquireToken` to
|
|
100
|
+
* apply any Intune conditional-access policies.
|
|
101
|
+
*
|
|
102
|
+
* On iOS: calls `IntuneMAMEnrollmentManager.registerAndEnrollAccount`.
|
|
103
|
+
* On Android: calls `MAMEnrollmentManager.registerAndEnrollAccount`.
|
|
104
|
+
*/
|
|
105
|
+
export async function registerAndEnrollAccount(params) {
|
|
106
|
+
await ExpoMsalIntuneModule.registerAndEnrollAccount(params.upn, params.aadId ?? '', params.tenantId ?? '');
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Remove an account from Intune MAM enrollment. Call this on sign-out.
|
|
111
|
+
*/
|
|
112
|
+
export async function deRegisterAndUnenrollAccount(upn) {
|
|
113
|
+
await ExpoMsalIntuneModule.deRegisterAndUnenrollAccount(upn);
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Compute the MSAL redirect URI from the app's own identity at runtime.
|
|
118
|
+
* - Android: `msauth://<packageName>/<base64-sha1-cert-hash>`
|
|
119
|
+
* - iOS: `msauth.<bundleId>://auth`
|
|
120
|
+
*
|
|
121
|
+
* Synchronous. Use this instead of a hardcoded redirect URI in auth.config.json
|
|
122
|
+
* so the wrap script never needs to patch the Hermes bytecode bundle.
|
|
123
|
+
*/
|
|
124
|
+
export function computeMsalRedirectUri() {
|
|
125
|
+
return ExpoMsalIntuneModule.computeMsalRedirectUri();
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
/**
|
|
129
|
+
* Read pipeline-patchable auth configuration from native platform sources at
|
|
130
|
+
* runtime.
|
|
131
|
+
*
|
|
132
|
+
* - Android: reads `adal_client_id` / `adal_redirect_uri` string resources
|
|
133
|
+
* patched in `resources.pb` by the production AAB+protoc pipeline.
|
|
134
|
+
* - iOS: reads `ADALClientId` / `ADALRedirectUri` from `Info.plist`
|
|
135
|
+
* `IntuneMAMSettings`, patched by the pipeline via `plutil -replace`.
|
|
136
|
+
* The Intune MAM SDK also reads these keys natively for enrollment.
|
|
137
|
+
*
|
|
138
|
+
* Synchronous — no I/O after the first call (OS caches resource lookups).
|
|
139
|
+
*
|
|
140
|
+
* **Usage pattern (in AuthContext):**
|
|
141
|
+
* ```ts
|
|
142
|
+
* const wrapCfg = getWrapConfig();
|
|
143
|
+
* // Placeholder tag means base build not yet wrapped; fall back to auth.config.json.
|
|
144
|
+
* const clientId = (wrapCfg.clientId && !wrapCfg.clientId.includes('_TAG'))
|
|
145
|
+
* ? wrapCfg.clientId
|
|
146
|
+
* : msalConfig.clientId;
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
export function getWrapConfig() {
|
|
150
|
+
return ExpoMsalIntuneModule.getWrapConfig();
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
// Default export matches react-native-msal's default export.
|
|
154
|
+
export default PublicClientApplication;
|
|
155
|
+
|
|
156
|
+
// ---------------------------------------------------------------------------
|
|
157
|
+
// initializeFromConfig
|
|
158
|
+
// ---------------------------------------------------------------------------
|
|
159
|
+
|
|
160
|
+
/**
|
|
161
|
+
* Create and initialize a `PublicClientApplication` from an `AuthConfig`
|
|
162
|
+
* object — typically imported directly from `auth.config.json`.
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```ts
|
|
166
|
+
* import authConfig from '../auth.config.json';
|
|
167
|
+
* import { initializeFromConfig } from '@microsoft/power-apps-native-auth';
|
|
168
|
+
*
|
|
169
|
+
* const pca = await initializeFromConfig(authConfig);
|
|
170
|
+
* ```
|
|
171
|
+
*/
|
|
172
|
+
export async function initializeFromConfig(config) {
|
|
173
|
+
const authority = `https://login.microsoftonline.com/${config.msal.tenantId}`;
|
|
174
|
+
const pca = new PublicClientApplication({
|
|
175
|
+
auth: {
|
|
176
|
+
clientId: config.msal.clientId,
|
|
177
|
+
authority,
|
|
178
|
+
redirectUri: config.msal.redirectUri
|
|
179
|
+
},
|
|
180
|
+
useBroker: config.msal.useBroker ?? false,
|
|
181
|
+
androidConfigOptions: {
|
|
182
|
+
authorization_user_agent: config.msal.useEmbeddedWebView ? 'WEBVIEW' : 'BROWSER'
|
|
183
|
+
}
|
|
184
|
+
});
|
|
185
|
+
await pca.init();
|
|
186
|
+
return pca;
|
|
187
|
+
}
|
|
188
|
+
|
|
189
|
+
/**
|
|
190
|
+
* Build a `MSALPublicClientApplicationConfig` from an `AuthConfig` without
|
|
191
|
+
* creating or initializing a PCA instance. Useful when you need the raw config
|
|
192
|
+
* object (e.g. to pass into a custom auth module).
|
|
193
|
+
*/
|
|
194
|
+
export function buildMsalConfig(config) {
|
|
195
|
+
const authority = `https://login.microsoftonline.com/${config.msal.tenantId}`;
|
|
196
|
+
return {
|
|
197
|
+
auth: {
|
|
198
|
+
clientId: config.msal.clientId,
|
|
199
|
+
authority,
|
|
200
|
+
redirectUri: config.msal.redirectUri
|
|
201
|
+
},
|
|
202
|
+
useBroker: config.msal.useBroker ?? false,
|
|
203
|
+
androidConfigOptions: {
|
|
204
|
+
authorization_user_agent: config.msal.useEmbeddedWebView ? 'WEBVIEW' : 'BROWSER'
|
|
205
|
+
}
|
|
206
|
+
};
|
|
207
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"module"}
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* power-apps-native-auth — AuthConfig type.
|
|
3
|
+
*
|
|
4
|
+
* Describes the shape of auth.config.json in the consuming app.
|
|
5
|
+
* Only contains values that are read purely at JS runtime — changing any
|
|
6
|
+
* of these does NOT require rebuilding the dev client.
|
|
7
|
+
*
|
|
8
|
+
* Values that ARE baked into the native binary (app.json scheme,
|
|
9
|
+
* AndroidManifest intent-filters, iOS URL schemes) must NOT appear here.
|
|
10
|
+
*/
|
|
11
|
+
export interface MsalAuthConfig {
|
|
12
|
+
/** Azure AD app registration client ID. */
|
|
13
|
+
clientId: string;
|
|
14
|
+
/**
|
|
15
|
+
* Entra tenant ID, or `'organizations'` for any work/school account,
|
|
16
|
+
* or `'common'` for personal + work accounts.
|
|
17
|
+
*/
|
|
18
|
+
tenantId: string;
|
|
19
|
+
/**
|
|
20
|
+
* Optional redirect URI override. When omitted the MSAL library uses its
|
|
21
|
+
* platform-default redirect URI (e.g. `msal<clientId>://auth` on mobile).
|
|
22
|
+
*/
|
|
23
|
+
redirectUri?: string;
|
|
24
|
+
/**
|
|
25
|
+
* Android only. Use the embedded WebView instead of a Custom Tab / system
|
|
26
|
+
* browser. Keep `true` during dev-client development to avoid needing a
|
|
27
|
+
* `BrowserTabActivity` entry in the manifest.
|
|
28
|
+
* Passed as a runtime flag to the native module — no manifest change needed.
|
|
29
|
+
*
|
|
30
|
+
* Do NOT set this in auth.config.json — it is computed at runtime in
|
|
31
|
+
* _layout.tsx as `__DEV__` (true in dev client, false in release builds).
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
useEmbeddedWebView?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* Use the Microsoft Authenticator / Company Portal broker for auth.
|
|
37
|
+
* On iOS: enables `MSALBrokerAvailability.msalOnly` + requires
|
|
38
|
+
* `msauth.<bundleId>://auth` in `CFBundleURLTypes` (added by wrap pipeline).
|
|
39
|
+
* On Android: sets `broker_redirect_uri_registered: true` + requires
|
|
40
|
+
* `BrowserTabActivity` intent-filter (added by wrap pipeline).
|
|
41
|
+
*
|
|
42
|
+
* Do NOT set this in auth.config.json — it is computed at runtime in
|
|
43
|
+
* _layout.tsx as `!__DEV__` (false in dev client, true in release builds).
|
|
44
|
+
* @default false
|
|
45
|
+
*/
|
|
46
|
+
useBroker?: boolean;
|
|
47
|
+
}
|
|
48
|
+
export interface IntuneConfig {
|
|
49
|
+
/**
|
|
50
|
+
* When `true`, the signed-in account is registered with Intune MAM
|
|
51
|
+
* immediately after a successful interactive sign-in.
|
|
52
|
+
* This is a JS-only flag — toggling it does not require a native rebuild,
|
|
53
|
+
* but the Intune SDK must already be linked in the dev client.
|
|
54
|
+
*
|
|
55
|
+
* Do NOT set this in auth.config.json — it is computed at runtime in
|
|
56
|
+
* _layout.tsx as `!__DEV__` (false in dev client, true in release builds).
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
enabled?: boolean;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Full shape of `auth.config.json` in the consuming Expo app.
|
|
63
|
+
* Every property here is safe to change without a native rebuild.
|
|
64
|
+
*
|
|
65
|
+
* Note: `environmentId` and `region` live in `power.config.json` (generated
|
|
66
|
+
* by `pac code init`) and are NOT part of this config.
|
|
67
|
+
*/
|
|
68
|
+
export interface AuthConfig {
|
|
69
|
+
msal: MsalAuthConfig;
|
|
70
|
+
/**
|
|
71
|
+
* Intune MAM configuration. Omit from auth.config.json — `enabled` is
|
|
72
|
+
* computed automatically at runtime from `!__DEV__`.
|
|
73
|
+
*/
|
|
74
|
+
intune?: IntuneConfig;
|
|
75
|
+
}
|
|
76
|
+
//# sourceMappingURL=AuthConfig.types.d.ts.map
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* power-apps-native-auth — shared type definitions.
|
|
3
|
+
*
|
|
4
|
+
* These types are intentionally compatible with react-native-msal's public
|
|
5
|
+
* surface so that existing code relying on those types continues to compile
|
|
6
|
+
* without modification.
|
|
7
|
+
*/
|
|
8
|
+
export interface MSALAccount {
|
|
9
|
+
/** Unique account identifier (home account id). */
|
|
10
|
+
identifier: string;
|
|
11
|
+
/** User principal name / email. */
|
|
12
|
+
username: string;
|
|
13
|
+
/** Tenant in which the account is registered. */
|
|
14
|
+
tenantId: string;
|
|
15
|
+
/** Optional decoded ID-token claims. */
|
|
16
|
+
claims?: Record<string, unknown>;
|
|
17
|
+
}
|
|
18
|
+
export interface MSALInteractiveParams {
|
|
19
|
+
scopes: string[];
|
|
20
|
+
/** Pre-fill the sign-in email field. */
|
|
21
|
+
loginHint?: string;
|
|
22
|
+
/** OAuth2 prompt: 'login' | 'consent' | 'select_account' | 'none'. */
|
|
23
|
+
prompt?: string;
|
|
24
|
+
/** Extra query parameters appended to the authorization URL. */
|
|
25
|
+
extraQueryParameters?: Record<string, string>;
|
|
26
|
+
}
|
|
27
|
+
export interface MSALSilentParams {
|
|
28
|
+
scopes: string[];
|
|
29
|
+
/** The account to refresh a token for. */
|
|
30
|
+
account: MSALAccount;
|
|
31
|
+
/** Force a network call even when a cached token exists. */
|
|
32
|
+
forceRefresh?: boolean;
|
|
33
|
+
}
|
|
34
|
+
export interface MSALSignoutParams {
|
|
35
|
+
account: MSALAccount;
|
|
36
|
+
/** Sign out from the browser / SSO session as well. */
|
|
37
|
+
signoutFromBrowser?: boolean;
|
|
38
|
+
}
|
|
39
|
+
export interface MSALResult {
|
|
40
|
+
accessToken: string;
|
|
41
|
+
idToken?: string;
|
|
42
|
+
account: MSALAccount;
|
|
43
|
+
/** Expiry time as a Unix millisecond timestamp. */
|
|
44
|
+
expiresOn: number;
|
|
45
|
+
scopes: string[];
|
|
46
|
+
}
|
|
47
|
+
export interface MSALPublicClientApplicationConfig {
|
|
48
|
+
auth: {
|
|
49
|
+
clientId: string;
|
|
50
|
+
authority: string;
|
|
51
|
+
redirectUri?: string;
|
|
52
|
+
};
|
|
53
|
+
/**
|
|
54
|
+
* Use the Microsoft Authenticator / Company Portal broker for auth.
|
|
55
|
+
* Requires broker URL schemes baked into the native binary — keep `false`
|
|
56
|
+
* for dev client builds. The wrap pipeline sets this `true` in production.
|
|
57
|
+
* @default false
|
|
58
|
+
*/
|
|
59
|
+
useBroker?: boolean;
|
|
60
|
+
/**
|
|
61
|
+
* Android-specific options forwarded to the native MSAL configuration.
|
|
62
|
+
* Has no effect on iOS.
|
|
63
|
+
*/
|
|
64
|
+
androidConfigOptions?: {
|
|
65
|
+
/**
|
|
66
|
+
* `'WEBVIEW'` — use an embedded WebView (avoids BrowserTabActivity).
|
|
67
|
+
* `'BROWSER'` — use the system browser (default).
|
|
68
|
+
*/
|
|
69
|
+
authorization_user_agent?: 'WEBVIEW' | 'BROWSER';
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
export interface IntuneEnrollmentParams {
|
|
73
|
+
/** User Principal Name of the account to enroll. */
|
|
74
|
+
upn: string;
|
|
75
|
+
/** Azure AD account identifier (oid). */
|
|
76
|
+
aadId?: string;
|
|
77
|
+
/** Tenant ID. */
|
|
78
|
+
tenantId?: string;
|
|
79
|
+
}
|
|
80
|
+
//# sourceMappingURL=ExpoMsalIntune.types.d.ts.map
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* power-apps-native-auth — native module bindings.
|
|
3
|
+
*
|
|
4
|
+
* This module is resolved at runtime via expo-modules-core. On iOS and
|
|
5
|
+
* Android it delegates to the native implementations; on web or in test
|
|
6
|
+
* environments it throws, which surfaces as a clear error rather than a
|
|
7
|
+
* silent no-op.
|
|
8
|
+
*/
|
|
9
|
+
import type { MSALAccount, MSALResult } from './ExpoMsalIntune.types';
|
|
10
|
+
export interface NativeAccount {
|
|
11
|
+
identifier: string;
|
|
12
|
+
username: string;
|
|
13
|
+
tenantId: string;
|
|
14
|
+
claims: string;
|
|
15
|
+
}
|
|
16
|
+
export interface NativeTokenResult {
|
|
17
|
+
accessToken: string;
|
|
18
|
+
idToken: string;
|
|
19
|
+
expiresOn: number;
|
|
20
|
+
scopes: string[];
|
|
21
|
+
account: NativeAccount;
|
|
22
|
+
}
|
|
23
|
+
export interface NativeExpoMsalIntuneModule {
|
|
24
|
+
/**
|
|
25
|
+
* Initialize the MSAL PublicClientApplication with the provided config.
|
|
26
|
+
* Must be called before any token acquisition.
|
|
27
|
+
*/
|
|
28
|
+
initializeClient(clientId: string, authority: string, redirectUri: string, useEmbeddedWebView: boolean, useBroker: boolean): Promise<void>;
|
|
29
|
+
/**
|
|
30
|
+
* Launch an interactive sign-in/consent flow.
|
|
31
|
+
*/
|
|
32
|
+
acquireTokenInteractive(scopes: string[], loginHint: string | null, prompt: string | null): Promise<NativeTokenResult>;
|
|
33
|
+
/**
|
|
34
|
+
* Silently refresh a token from the MSAL cache / broker.
|
|
35
|
+
* Throws `MSALError.noAccountFound` / `MSALError.interactionRequired` when
|
|
36
|
+
* the cache cannot satisfy the request — callers should fall back to
|
|
37
|
+
* `acquireTokenInteractive`.
|
|
38
|
+
*/
|
|
39
|
+
acquireTokenSilent(scopes: string[], accountIdentifier: string, forceRefresh: boolean): Promise<NativeTokenResult>;
|
|
40
|
+
/** Return all accounts cached in the MSAL token cache. */
|
|
41
|
+
getAccounts(): Promise<NativeAccount[]>;
|
|
42
|
+
/**
|
|
43
|
+
* Remove the account from the MSAL cache and, optionally, the browser
|
|
44
|
+
* SSO session.
|
|
45
|
+
*/
|
|
46
|
+
signOut(accountIdentifier: string, signoutFromBrowser: boolean): Promise<void>;
|
|
47
|
+
/**
|
|
48
|
+
* Register the signed-in account with Intune MAM and trigger enrollment.
|
|
49
|
+
* On iOS this calls IntuneMAMEnrollmentManager.registerAndEnrollAccount.
|
|
50
|
+
* On Android this calls MAMEnrollmentManager.registerAndEnrollAccount.
|
|
51
|
+
*/
|
|
52
|
+
registerAndEnrollAccount(upn: string, aadId: string, tenantId: string): Promise<void>;
|
|
53
|
+
/**
|
|
54
|
+
* Remove the account from Intune MAM enrollment.
|
|
55
|
+
*/
|
|
56
|
+
deRegisterAndUnenrollAccount(upn: string): Promise<void>;
|
|
57
|
+
/**
|
|
58
|
+
* Compute the MSAL redirect URI from the app's own identity at runtime.
|
|
59
|
+
* Android: msauth://<packageName>/<base64-sha1-cert-hash>
|
|
60
|
+
* iOS: msauth.<bundleId>://auth
|
|
61
|
+
*
|
|
62
|
+
* Synchronous — no network or disk I/O. Call this instead of reading a
|
|
63
|
+
* hardcoded redirect URI from auth.config.json so that the wrap script
|
|
64
|
+
* does not need to patch the Hermes bytecode bundle.
|
|
65
|
+
*/
|
|
66
|
+
computeMsalRedirectUri(): string;
|
|
67
|
+
/**
|
|
68
|
+
* Read pipeline-patchable auth configuration from native platform sources
|
|
69
|
+
* at runtime (Android: string resources; iOS: Info.plist IntuneMAMSettings).
|
|
70
|
+
*
|
|
71
|
+
* The production AAB+protoc pipeline replaces placeholder values in these
|
|
72
|
+
* sources before distribution. Calling this in release builds allows the
|
|
73
|
+
* app to use the correct customer-specific values without ever patching
|
|
74
|
+
* the Hermes bytecode bundle.
|
|
75
|
+
*
|
|
76
|
+
* Synchronous — reads from memory-mapped resources / Bundle, no I/O.
|
|
77
|
+
*
|
|
78
|
+
* Returns empty strings for keys that have not been patched (base build
|
|
79
|
+
* before wrapping). Callers should fall back to auth.config.json values
|
|
80
|
+
* when the returned clientId is empty or still contains a placeholder tag.
|
|
81
|
+
*/
|
|
82
|
+
getWrapConfig(): {
|
|
83
|
+
clientId: string;
|
|
84
|
+
redirectUri: string;
|
|
85
|
+
tenantId: string;
|
|
86
|
+
};
|
|
87
|
+
}
|
|
88
|
+
declare const ExpoMsalIntuneModule: NativeExpoMsalIntuneModule;
|
|
89
|
+
export declare function mapNativeAccount(native: NativeAccount): MSALAccount;
|
|
90
|
+
export declare function mapNativeResult(native: NativeTokenResult): MSALResult;
|
|
91
|
+
export default ExpoMsalIntuneModule;
|
|
92
|
+
//# sourceMappingURL=ExpoMsalIntuneModule.d.ts.map
|
|
@@ -0,0 +1,125 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* power-apps-native-auth — public API.
|
|
3
|
+
*
|
|
4
|
+
* Drop-in replacement for react-native-msal: exports a default
|
|
5
|
+
* `PublicClientApplication` class with the same interface used by
|
|
6
|
+
* power-apps-native-player/src/auth/msalAuth.native.ts, plus Intune MAM
|
|
7
|
+
* helpers for enrollment/unenrollment.
|
|
8
|
+
*
|
|
9
|
+
* Metro alias (metro.config.js):
|
|
10
|
+
* 'react-native-msal' → '@microsoft/power-apps-native-auth'
|
|
11
|
+
*
|
|
12
|
+
* This means the tarball's msalAuth.native.ts continues to work without
|
|
13
|
+
* patching.
|
|
14
|
+
*
|
|
15
|
+
*/
|
|
16
|
+
import type { MSALAccount, MSALInteractiveParams, MSALPublicClientApplicationConfig, MSALResult, MSALSignoutParams, MSALSilentParams, IntuneEnrollmentParams } from './ExpoMsalIntune.types';
|
|
17
|
+
import type { AuthConfig } from './AuthConfig.types';
|
|
18
|
+
export type { MSALAccount, MSALInteractiveParams, MSALPublicClientApplicationConfig, MSALResult, MSALSignoutParams, MSALSilentParams, IntuneEnrollmentParams, };
|
|
19
|
+
export type { AuthConfig, MsalAuthConfig, IntuneConfig } from './AuthConfig.types';
|
|
20
|
+
/**
|
|
21
|
+
* Wraps the native MSAL PublicClientApplication. Construct once, call
|
|
22
|
+
* `init()`, then reuse for the app's lifetime.
|
|
23
|
+
*
|
|
24
|
+
* API is intentionally compatible with react-native-msal v4 so that existing
|
|
25
|
+
* callers require zero changes.
|
|
26
|
+
*/
|
|
27
|
+
export declare class PublicClientApplication {
|
|
28
|
+
private readonly _config;
|
|
29
|
+
private _initialized;
|
|
30
|
+
constructor(config: MSALPublicClientApplicationConfig);
|
|
31
|
+
/** True after `init()` has completed successfully. */
|
|
32
|
+
get isInitialized(): boolean;
|
|
33
|
+
/**
|
|
34
|
+
* Create the native MSAL PCA instance. Must be called before any other
|
|
35
|
+
* method.
|
|
36
|
+
*/
|
|
37
|
+
init(): Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Launch an interactive sign-in / consent dialog.
|
|
40
|
+
*/
|
|
41
|
+
acquireToken(params: MSALInteractiveParams): Promise<MSALResult>;
|
|
42
|
+
/**
|
|
43
|
+
* Silently acquire a token from the MSAL cache or broker.
|
|
44
|
+
* Falls back to interactive if the cache cannot satisfy the request — the
|
|
45
|
+
* caller should catch `MSALError.interactionRequired` and call
|
|
46
|
+
* `acquireToken` instead.
|
|
47
|
+
*/
|
|
48
|
+
acquireTokenSilent(params: MSALSilentParams): Promise<MSALResult>;
|
|
49
|
+
/** Return all accounts from the MSAL token cache. */
|
|
50
|
+
getAccounts(): Promise<MSALAccount[]>;
|
|
51
|
+
/**
|
|
52
|
+
* Remove the account from the MSAL cache and optionally end the browser
|
|
53
|
+
* SSO session.
|
|
54
|
+
*/
|
|
55
|
+
signOut(params: MSALSignoutParams): Promise<boolean>;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* Register a signed-in account with Intune MAM and initiate device/app
|
|
59
|
+
* enrollment. Call this immediately after a successful `acquireToken` to
|
|
60
|
+
* apply any Intune conditional-access policies.
|
|
61
|
+
*
|
|
62
|
+
* On iOS: calls `IntuneMAMEnrollmentManager.registerAndEnrollAccount`.
|
|
63
|
+
* On Android: calls `MAMEnrollmentManager.registerAndEnrollAccount`.
|
|
64
|
+
*/
|
|
65
|
+
export declare function registerAndEnrollAccount(params: IntuneEnrollmentParams): Promise<void>;
|
|
66
|
+
/**
|
|
67
|
+
* Remove an account from Intune MAM enrollment. Call this on sign-out.
|
|
68
|
+
*/
|
|
69
|
+
export declare function deRegisterAndUnenrollAccount(upn: string): Promise<void>;
|
|
70
|
+
/**
|
|
71
|
+
* Compute the MSAL redirect URI from the app's own identity at runtime.
|
|
72
|
+
* - Android: `msauth://<packageName>/<base64-sha1-cert-hash>`
|
|
73
|
+
* - iOS: `msauth.<bundleId>://auth`
|
|
74
|
+
*
|
|
75
|
+
* Synchronous. Use this instead of a hardcoded redirect URI in auth.config.json
|
|
76
|
+
* so the wrap script never needs to patch the Hermes bytecode bundle.
|
|
77
|
+
*/
|
|
78
|
+
export declare function computeMsalRedirectUri(): string;
|
|
79
|
+
/**
|
|
80
|
+
* Read pipeline-patchable auth configuration from native platform sources at
|
|
81
|
+
* runtime.
|
|
82
|
+
*
|
|
83
|
+
* - Android: reads `adal_client_id` / `adal_redirect_uri` string resources
|
|
84
|
+
* patched in `resources.pb` by the production AAB+protoc pipeline.
|
|
85
|
+
* - iOS: reads `ADALClientId` / `ADALRedirectUri` from `Info.plist`
|
|
86
|
+
* `IntuneMAMSettings`, patched by the pipeline via `plutil -replace`.
|
|
87
|
+
* The Intune MAM SDK also reads these keys natively for enrollment.
|
|
88
|
+
*
|
|
89
|
+
* Synchronous — no I/O after the first call (OS caches resource lookups).
|
|
90
|
+
*
|
|
91
|
+
* **Usage pattern (in AuthContext):**
|
|
92
|
+
* ```ts
|
|
93
|
+
* const wrapCfg = getWrapConfig();
|
|
94
|
+
* // Placeholder tag means base build not yet wrapped; fall back to auth.config.json.
|
|
95
|
+
* const clientId = (wrapCfg.clientId && !wrapCfg.clientId.includes('_TAG'))
|
|
96
|
+
* ? wrapCfg.clientId
|
|
97
|
+
* : msalConfig.clientId;
|
|
98
|
+
* ```
|
|
99
|
+
*/
|
|
100
|
+
export declare function getWrapConfig(): {
|
|
101
|
+
clientId: string;
|
|
102
|
+
redirectUri: string;
|
|
103
|
+
tenantId: string;
|
|
104
|
+
};
|
|
105
|
+
export default PublicClientApplication;
|
|
106
|
+
/**
|
|
107
|
+
* Create and initialize a `PublicClientApplication` from an `AuthConfig`
|
|
108
|
+
* object — typically imported directly from `auth.config.json`.
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```ts
|
|
112
|
+
* import authConfig from '../auth.config.json';
|
|
113
|
+
* import { initializeFromConfig } from '@microsoft/power-apps-native-auth';
|
|
114
|
+
*
|
|
115
|
+
* const pca = await initializeFromConfig(authConfig);
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
export declare function initializeFromConfig(config: AuthConfig): Promise<PublicClientApplication>;
|
|
119
|
+
/**
|
|
120
|
+
* Build a `MSALPublicClientApplicationConfig` from an `AuthConfig` without
|
|
121
|
+
* creating or initializing a PCA instance. Useful when you need the raw config
|
|
122
|
+
* object (e.g. to pass into a custom auth module).
|
|
123
|
+
*/
|
|
124
|
+
export declare function buildMsalConfig(config: AuthConfig): MSALPublicClientApplicationConfig;
|
|
125
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"type":"commonjs"}
|