react-native-oauth-essentials 1.0.11 → 1.1.1

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.
Files changed (51) hide show
  1. package/README.md +384 -362
  2. package/android/src/main/java/com/oauthessentials/CredentialError.kt +4 -1
  3. package/android/src/main/java/com/oauthessentials/CredentialFactory.kt +24 -2
  4. package/android/src/main/java/com/oauthessentials/CustomTabsActivity.kt +14 -1
  5. package/android/src/main/java/com/oauthessentials/OauthEssentialsModule.kt +448 -192
  6. package/app.plugin.js +1 -0
  7. package/ios/AppleIdRetriever.swift +25 -26
  8. package/ios/CredentialError.swift +3 -0
  9. package/ios/CredentialFactory.swift +38 -20
  10. package/ios/CredentialsType.swift +1 -0
  11. package/ios/GoogleIdRetriever.swift +132 -56
  12. package/ios/HybridRetriever.swift +12 -18
  13. package/ios/OauthEssentials.h +0 -3
  14. package/ios/OauthEssentials.mm +45 -2
  15. package/ios/OauthEssentialsModule.swift +266 -57
  16. package/ios/PasskeyRetriever.swift +31 -49
  17. package/ios/PasswordRetriever.swift +10 -30
  18. package/ios/RCTPromiseSettler.swift +125 -0
  19. package/jest/index.js +149 -0
  20. package/lib/module/NativeOauthEssentials.js +10 -1
  21. package/lib/module/NativeOauthEssentials.js.map +1 -1
  22. package/lib/module/errors.js +38 -0
  23. package/lib/module/errors.js.map +1 -0
  24. package/lib/module/index.js +432 -58
  25. package/lib/module/index.js.map +1 -1
  26. package/lib/module/oauth.js +97 -0
  27. package/lib/module/oauth.js.map +1 -0
  28. package/lib/module/platform.js +108 -0
  29. package/lib/module/platform.js.map +1 -0
  30. package/lib/module/types.js +46 -1
  31. package/lib/module/types.js.map +1 -1
  32. package/lib/typescript/src/NativeOauthEssentials.d.ts +70 -16
  33. package/lib/typescript/src/NativeOauthEssentials.d.ts.map +1 -1
  34. package/lib/typescript/src/errors.d.ts +18 -0
  35. package/lib/typescript/src/errors.d.ts.map +1 -0
  36. package/lib/typescript/src/index.d.ts +235 -40
  37. package/lib/typescript/src/index.d.ts.map +1 -1
  38. package/lib/typescript/src/oauth.d.ts +32 -0
  39. package/lib/typescript/src/oauth.d.ts.map +1 -0
  40. package/lib/typescript/src/platform.d.ts +39 -0
  41. package/lib/typescript/src/platform.d.ts.map +1 -0
  42. package/lib/typescript/src/types.d.ts +190 -3
  43. package/lib/typescript/src/types.d.ts.map +1 -1
  44. package/package.json +8 -4
  45. package/plugin/withOauthEssentials.js +291 -0
  46. package/src/NativeOauthEssentials.ts +91 -17
  47. package/src/errors.ts +49 -0
  48. package/src/index.tsx +587 -80
  49. package/src/oauth.ts +140 -0
  50. package/src/platform.ts +121 -0
  51. package/src/types.ts +200 -2
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+
3
+ import { createCredentialError } from "./errors.js";
4
+ import { warnOnce } from "./platform.js";
5
+ import { CredentialError } from "./types.js";
6
+ function encodeQuery(params) {
7
+ return Object.keys(params).map(key => `${encodeURIComponent(key)}=${encodeURIComponent(params[key])}`).join('&');
8
+ }
9
+
10
+ /**
11
+ * Decodes a query component, keeping it raw when its percent-encoding is malformed (`50%off`), so
12
+ * a provider bug does not turn into an error without `code`.
13
+ */
14
+ function decodeComponent(value) {
15
+ const spaced = value.replace(/\+/g, ' ');
16
+ try {
17
+ return decodeURIComponent(spaced);
18
+ } catch {
19
+ return spaced;
20
+ }
21
+ }
22
+
23
+ /**
24
+ * Set by the library and checked or reused later (state, PKCE, token exchange), so
25
+ * `additionalParameters` cannot override them.
26
+ */
27
+ export const RESERVED_AUTHORIZATION_PARAMS = ['response_type', 'client_id', 'redirect_uri', 'state', 'code_challenge', 'code_challenge_method'];
28
+ export function buildAuthorizationUrl(p) {
29
+ const params = {
30
+ response_type: 'code',
31
+ client_id: p.clientId,
32
+ redirect_uri: p.redirectUri,
33
+ state: p.state
34
+ };
35
+ if (p.scopes && p.scopes.length > 0) {
36
+ params.scope = p.scopes.join(' ');
37
+ }
38
+ if (p.codeChallenge) {
39
+ params.code_challenge = p.codeChallenge;
40
+ params.code_challenge_method = 'S256';
41
+ }
42
+ const reserved = RESERVED_AUTHORIZATION_PARAMS;
43
+ for (const [key, value] of Object.entries(p.additionalParameters ?? {})) {
44
+ if (reserved.includes(key)) {
45
+ warnOnce('oauthSignIn', `additionalParameters.${key}`, `additionalParameters.${key} is ignored: the library sets it (use the matching option instead).`);
46
+ continue;
47
+ }
48
+ params[key] = value;
49
+ }
50
+ const separator = p.authorizationEndpoint.includes('?') ? '&' : '?';
51
+ return `${p.authorizationEndpoint}${separator}${encodeQuery(params)}`;
52
+ }
53
+
54
+ /**
55
+ * Reads the query and fragment parameters of a redirect url.
56
+ */
57
+ export function parseRedirectParams(url) {
58
+ const params = {};
59
+ const queryStart = url.indexOf('?');
60
+ const hashStart = url.indexOf('#');
61
+ const parts = [];
62
+ if (queryStart >= 0) {
63
+ parts.push(url.slice(queryStart + 1, hashStart > queryStart ? hashStart : undefined));
64
+ }
65
+ if (hashStart >= 0) {
66
+ parts.push(url.slice(hashStart + 1));
67
+ }
68
+ for (const part of parts) {
69
+ for (const pair of part.split('&')) {
70
+ if (!pair) continue;
71
+ const eq = pair.indexOf('=');
72
+ const key = decodeComponent(eq >= 0 ? pair.slice(0, eq) : pair);
73
+ params[key] = eq >= 0 ? decodeComponent(pair.slice(eq + 1)) : '';
74
+ }
75
+ }
76
+ return params;
77
+ }
78
+ export function getUrlScheme(url) {
79
+ const index = url.indexOf(':');
80
+ if (index <= 0) {
81
+ throw createCredentialError(CredentialError.CONFIGURATION_ERROR, `Invalid redirect uri: ${url}`);
82
+ }
83
+ return url.slice(0, index);
84
+ }
85
+ export function buildTokenRequestBody(p) {
86
+ const params = {
87
+ grant_type: 'authorization_code',
88
+ code: p.code,
89
+ client_id: p.clientId,
90
+ redirect_uri: p.redirectUri
91
+ };
92
+ if (p.codeVerifier) {
93
+ params.code_verifier = p.codeVerifier;
94
+ }
95
+ return encodeQuery(params);
96
+ }
97
+ //# sourceMappingURL=oauth.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["createCredentialError","warnOnce","CredentialError","encodeQuery","params","Object","keys","map","key","encodeURIComponent","join","decodeComponent","value","spaced","replace","decodeURIComponent","RESERVED_AUTHORIZATION_PARAMS","buildAuthorizationUrl","p","response_type","client_id","clientId","redirect_uri","redirectUri","state","scopes","length","scope","codeChallenge","code_challenge","code_challenge_method","reserved","entries","additionalParameters","includes","separator","authorizationEndpoint","parseRedirectParams","url","queryStart","indexOf","hashStart","parts","push","slice","undefined","part","pair","split","eq","getUrlScheme","index","CONFIGURATION_ERROR","buildTokenRequestBody","grant_type","code","codeVerifier","code_verifier"],"sourceRoot":"../../src","sources":["oauth.ts"],"mappings":";;AAAA,SAASA,qBAAqB,QAAQ,aAAU;AAChD,SAASC,QAAQ,QAAQ,eAAY;AACrC,SAASC,eAAe,QAAQ,YAAS;AAkBzC,SAASC,WAAWA,CAACC,MAA8B,EAAU;EAC3D,OAAOC,MAAM,CAACC,IAAI,CAACF,MAAM,CAAC,CACvBG,GAAG,CACDC,GAAG,IAAK,GAAGC,kBAAkB,CAACD,GAAG,CAAC,IAAIC,kBAAkB,CAACL,MAAM,CAACI,GAAG,CAAE,CAAC,EACzE,CAAC,CACAE,IAAI,CAAC,GAAG,CAAC;AACd;;AAEA;AACA;AACA;AACA;AACA,SAASC,eAAeA,CAACC,KAAa,EAAU;EAC9C,MAAMC,MAAM,GAAGD,KAAK,CAACE,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC;EACxC,IAAI;IACF,OAAOC,kBAAkB,CAACF,MAAM,CAAC;EACnC,CAAC,CAAC,MAAM;IACN,OAAOA,MAAM;EACf;AACF;;AAEA;AACA;AACA;AACA;AACA,OAAO,MAAMG,6BAA6B,GAAG,CAC3C,eAAe,EACf,WAAW,EACX,cAAc,EACd,OAAO,EACP,gBAAgB,EAChB,uBAAuB,CACf;AAEV,OAAO,SAASC,qBAAqBA,CAACC,CAAyB,EAAU;EACvE,MAAMd,MAA8B,GAAG;IACrCe,aAAa,EAA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CAACnC,CAKrC,EAAU;EACT,MAAMd,MAA8B,GAAG;IACrCkD,UAAU,EAAE,oBAAoB;IAChCC,IAAI,EAAErC,CAAC,CAACqC,IAAI;IACZnC,SAAS,EAAEF,CAAC,CAACG,QAAQ;IACrBC,YAAY,EAAEJ,CAAC,CAACK;EAClB,CAAC;EACD,IAAIL,CAAC,CAACsC,YAAY,EAAE;IAClBpD,MAAM,CAACqD,aAAa,GAAGvC,CAAC,CAACsC,YAAY;EACvC;EACA,OAAOrD,WAAW,CAACC,MAAM,CAAC;AAC5B","ignoreList":[]}
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ /**
4
+ * Picks the client id the native module of `os` expects.
5
+ *
6
+ * A string is passed as is. With `{ iosClientId, webClientId }`, iOS gets `iosClientId` (or '' so
7
+ * the native side reads `GIDClientID` from Info.plist) and `webClientId` as the default
8
+ * `serverClientId`; Android gets `webClientId` (or '', which rejects with `CONFIGURATION_ERROR`).
9
+ */
10
+ export function resolveGoogleClientId(os, clientId, options) {
11
+ if (typeof clientId === 'string') {
12
+ return {
13
+ clientId,
14
+ options
15
+ };
16
+ }
17
+ const ids = clientId ?? {};
18
+ if (os === 'ios') {
19
+ const resolved = {
20
+ ...options
21
+ };
22
+ if (resolved.serverClientId === undefined && ids.webClientId) {
23
+ resolved.serverClientId = ids.webClientId;
24
+ }
25
+ return {
26
+ clientId: ids.iosClientId ?? '',
27
+ options: resolved
28
+ };
29
+ }
30
+ return {
31
+ clientId: ids.webClientId ?? '',
32
+ options
33
+ };
34
+ }
35
+
36
+ /**
37
+ * Splits the `(clientId?, options?)` arguments of the Google methods, which also accept
38
+ * `(options)`: an object with `iosClientId` or `webClientId` is the client id, any other object is
39
+ * the options. Without a client id the native side reads it from the app config (Info.plist,
40
+ * AndroidManifest meta-data or the Firebase files).
41
+ */
42
+ export function splitGoogleArgs(first, second) {
43
+ if (first === null || first === undefined) {
44
+ return {
45
+ clientId: undefined,
46
+ options: second
47
+ };
48
+ }
49
+ if (typeof first === 'string' || 'iosClientId' in first || 'webClientId' in first) {
50
+ return {
51
+ clientId: first,
52
+ options: second
53
+ };
54
+ }
55
+ return {
56
+ clientId: undefined,
57
+ options: first
58
+ };
59
+ }
60
+
61
+ /**
62
+ * Message thrown when the native module is not in the binary: Expo Go (which only ships the Expo
63
+ * SDK native modules) or an app that was not rebuilt after installing the library.
64
+ */
65
+ export function missingNativeModuleMessage() {
66
+ const expo = globalThis.expo;
67
+ if (expo?.modules?.ExpoGo) {
68
+ return 'react-native-oauth-essentials does not work in Expo Go, which only contains the Expo SDK ' + 'native code. Create a development build instead: `npx expo run:ios` / `npx expo run:android` ' + 'or `eas build --profile development`.';
69
+ }
70
+ return 'react-native-oauth-essentials: the native module "OauthEssentials" was not found. Rebuild the ' + 'app after installing the library (run `pod install` in ios/ and build again; reloading Metro is ' + 'not enough) and make sure the New Architecture is enabled. With Expo, use a development build ' + '(Expo Go is not supported).';
71
+ }
72
+ const warned = new Set();
73
+
74
+ /**
75
+ * In development, warns once per method and option that an option set by the app has no effect on
76
+ * the current platform. `options` must be the options as passed by the app (before defaults).
77
+ */
78
+ export function warnIgnored(method, platform, options, keys) {
79
+ if (!__DEV__ || !options) {
80
+ return;
81
+ }
82
+ for (const key of keys) {
83
+ if (options[key] !== undefined) {
84
+ warnOnce(method, key, `"${key}" is ignored on ${platformName(platform)}.`);
85
+ }
86
+ }
87
+ }
88
+ function platformName(platform) {
89
+ if (platform === 'ios') return 'iOS';
90
+ if (platform === 'android') return 'Android';
91
+ return platform;
92
+ }
93
+
94
+ /**
95
+ * In development, logs `message` once per method and key.
96
+ */
97
+ export function warnOnce(method, key, message) {
98
+ if (!__DEV__) {
99
+ return;
100
+ }
101
+ const id = `${method}:${key}`;
102
+ if (warned.has(id)) {
103
+ return;
104
+ }
105
+ warned.add(id);
106
+ console.warn(`[react-native-oauth-essentials] ${method}: ${message}`);
107
+ }
108
+ //# sourceMappingURL=platform.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"names":["resolveGoogleClientId","os","clientId","options","ids","resolved","serverClientId","undefined","webClientId","iosClientId","splitGoogleArgs","first","second","missingNativeModuleMessage","expo","globalThis","modules","ExpoGo","warned","Set","warnIgnored","method","platform","keys","__DEV__","key","warnOnce","platformName","message","id","has","add","console","warn"],"sourceRoot":"../../src","sources":["platform.ts"],"mappings":";;AAIA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASA,qBAAqBA,CACnCC,EAAM,EACNC,QAA2C,EAC3CC,OAAU,EACwB;EAClC,IAAI,OAAOD,QAAQ,KAAK,QAAQ,EAAE;IAChC,OAAO;MAAEA,QAAQ;MAAEC;IAAQ,CAAC;EAC9B;EACA,MAAMC,GAAG,GAAGF,QAAQ,IAAI,CAAC,CAAC;EAC1B,IAAID,EAAE,KAAK,KAAK,EAAE;IAChB,MAAMI,QAAQ,GAAG;MAAE,GAAGF;IAAQ,CAAC;IAC/B,IAAIE,QAAQ,CAACC,cAAc,KAAKC,SAAS,IAAIH,GAAG,CAACI,WAAW,EAAE;MAC5DH,QAAQ,CAACC,cAAc,GAAGF,GAAG,CAACI,WAAW;IAC3C;IACA,OAAO;MAAEN,QAAQ,EAAEE,GAAG,CAACK,WAAW,IAAI,EAAE;MAAEN,OAAO,EAAEE;IAAS,CAAC;EAC/D;EACA,OAAO;IAAEH,QAAQ,EAAEE,GAAG,CAACI,WAAW,IAAI,EAAE;IAAEL;EAAQ,CAAC;AACrD;;AAEA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,SAASO,eAAeA,CAC7BC,KAA4C,EAC5CC,MAAqB,EAC6C;EAClE,IAAID,KAAK,KAAK,IAAI,IAAIA,KAAK,KAAKJ,SAAS,EAAE;IACzC,OAAO;MAAEL,QAAQ,EAAEK,SAAS;MAAEJ,OAAO,EAAES;IAAO,CAAC;EACjD;EACA,IACE,OAAOD,KAAK,KAAK,QAAQ,IACzB,aAAa,IAAIA,KAAK,IACtB,aAAa,IAAIA,KAAK,EACtB;IACA,OAAO;MAA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AAIP,MAAM,CAACY,GAAG,CAACD,EAAE,CAAC,EAAE;IAClB;EACF;EACAX,MAAM,CAACa,GAAG,CAACF,EAAE,CAAC;EACdG,OAAO,CAACC,IAAI,CAAC,mCAAmCZ,MAAM,KAAKO,OAAO,EAAE,CAAC;AACvE","ignoreList":[]}
@@ -1,5 +1,17 @@
1
1
  "use strict";
2
2
 
3
+ /**
4
+ * Google OAuth client ids per platform, all from the same Google Cloud project.
5
+ *
6
+ * Both are optional: a missing id is read from the app config, which the Expo plugin writes (from
7
+ * its options or the Firebase files).
8
+ */
9
+
10
+ /**
11
+ * A {@link GoogleClientIds} object, or a single client id string, used as is on both platforms
12
+ * (it must be the iOS client id on iOS and the web client id on Android).
13
+ */
14
+
3
15
  export let CredentialsType = /*#__PURE__*/function (CredentialsType) {
4
16
  CredentialsType["GOOGLE_ID"] = "GOOGLE_ID";
5
17
  // GoogleId credentials type
@@ -11,13 +23,46 @@ export let CredentialsType = /*#__PURE__*/function (CredentialsType) {
11
23
  // Android AppleId credentials type
12
24
  CredentialsType["CANCELLED"] = "CANCELLED";
13
25
  // type when the user cancels it
14
- CredentialsType["PASSKEY"] = "PASSKEY"; // Passkey credential type
26
+ CredentialsType["PASSKEY"] = "PASSKEY";
27
+ // Passkey credential type
28
+ CredentialsType["OAUTH"] = "OAUTH"; // Generic OAuth2/OIDC authorization code
15
29
  return CredentialsType;
16
30
  }({});
31
+ export let AppleIdCredentialState = /*#__PURE__*/function (AppleIdCredentialState) {
32
+ AppleIdCredentialState["AUTHORIZED"] = "AUTHORIZED";
33
+ AppleIdCredentialState["REVOKED"] = "REVOKED";
34
+ AppleIdCredentialState["NOT_FOUND"] = "NOT_FOUND";
35
+ AppleIdCredentialState["TRANSFERRED"] = "TRANSFERRED";
36
+ return AppleIdCredentialState;
37
+ }({});
17
38
  export let CredentialError = /*#__PURE__*/function (CredentialError) {
39
+ /**
40
+ * @deprecated Never thrown: missing Play Services rejects with `NOT_SUPPORTED_ERROR`.
41
+ */
18
42
  CredentialError["NO_PLAY_SERVICES_ERROR"] = "NO_PLAY_SERVICES_ERROR";
43
+ /** No Android activity, or no iOS view controller attached to a window, to present the UI. */
19
44
  CredentialError["NO_ACTIVITY_ERROR"] = "NO_ACTIVITY_ERROR";
45
+ /** The provider failed or returned something unexpected; `message` has the native error. */
20
46
  CredentialError["INVALID_RESULT_ERROR"] = "INVALID_RESULT_ERROR";
47
+ /** There is no credential to return (no account / passkey / previous sign in). */
48
+ CredentialError["NO_SIGN_IN_AVAILABLE"] = "NO_SIGN_IN_AVAILABLE";
49
+ /** iOS: the same method (or method group) is still waiting for the previous call. */
50
+ CredentialError["SIMULTANEOUS_CALL_ERROR"] = "SIMULTANEOUS_CALL_ERROR";
51
+ /** The OS version, missing Play Services or the platform does not support the method. */
52
+ CredentialError["NOT_SUPPORTED_ERROR"] = "NOT_SUPPORTED_ERROR";
53
+ /** The browser session could not be opened (app in background, Guided Access, no browser). */
54
+ CredentialError["BROWSER_UNAVAILABLE"] = "BROWSER_UNAVAILABLE";
55
+ /**
56
+ * The app is misconfigured: missing Google client id, missing iOS URL scheme (the message has
57
+ * the exact scheme to add) or an invalid `redirectUri`.
58
+ */
59
+ CredentialError["CONFIGURATION_ERROR"] = "CONFIGURATION_ERROR";
60
+ /** `oauthSignIn`: the token endpoint request failed (offline, DNS, TLS...). */
61
+ CredentialError["NETWORK_ERROR"] = "NETWORK_ERROR";
21
62
  return CredentialError;
22
63
  }({});
64
+
65
+ /** A {@link CredentialError} value, as an enum member or its string. */
66
+
67
+ /** Every promise of the library rejects with an `Error` that has one of these codes. */
23
68
  //# sourceMappingURL=types.js.map
@@ -1 +1 @@
1
- {"version":3,"names":["CredentialsType","CredentialError"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAiEA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EACA;EADfA,eAAe;EAEF;EAFbA,eAAe;EAGF;EAHbA,eAAe;EAIM;EAJrBA,eAAe;EAKA;EALfA,eAAe,yBAMJ;EAAA,OANXA,eAAe;AAAA;AAS3B,WAAYC,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAfA,eAAe;EAAA,OAAfA,eAAe;AAAA","ignoreList":[]}
1
+ {"version":3,"names":["CredentialsType","AppleIdCredentialState","CredentialError"],"sourceRoot":"../../src","sources":["types.ts"],"mappings":";;AAmDA;AACA;AACA;AACA;AACA;AACA;;AAiBA;AACA;AACA;AACA;;AAuJA,WAAYA,eAAe,0BAAfA,eAAe;EAAfA,eAAe;EACA;EADfA,eAAe;EAEF;EAFbA,eAAe;EAGF;EAHbA,eAAe;EAIM;EAJrBA,eAAe;EAKA;EALfA,eAAe;EAMJ;EANXA,eAAe,qBAOR;EAAA,OAPPA,eAAe;AAAA;AAU3B,WAAYC,sBAAsB,0BAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAtBA,sBAAsB;EAAA,OAAtBA,sBAAsB;AAAA;AAOlC,WAAYC,eAAe,0BAAfA,eAAe;EACzB;AACF;AACA;EAHYA,eAAe;EAKzB;EALUA,eAAe;EAOzB;EAPUA,eAAe;EASzB;EATUA,eAAe;EAWzB;EAXUA,eAAe;EAazB;EAbUA,eAAe;EAezB;EAfUA,eAAe;EAiBzB;AACF;AACA;AACA;EApBYA,eAAe;EAsBzB;EAtBUA,eAAe;EAAA,OAAfA,eAAe;AAAA;;AA0B3B;;AAGA","ignoreList":[]}
@@ -1,7 +1,14 @@
1
1
  import { type CodegenTypes, type TurboModule } from 'react-native';
2
2
  export interface Spec extends TurboModule {
3
+ /** Emitted with the `{ type, data }` a credential method resolves with, including `CANCELLED`. */
3
4
  readonly onCredentialSuccess: CodegenTypes.EventEmitter<CredentialSuccessEvent>;
5
+ /** Emitted with `{ code, message }` when a credential method rejects. */
4
6
  readonly onCredentialFailure: CodegenTypes.EventEmitter<CredentialErrorEvent>;
7
+ /** iOS only: emitted with `{ type: 'REVOKED' }` on `credentialRevokedNotification`. */
8
+ readonly onAppleIdCredentialRevoked: CodegenTypes.EventEmitter<AppleIdCredentialRevokedEvent>;
9
+ /**
10
+ * Read once when the module loads. See the exported constants in `index.tsx` for the values.
11
+ */
5
12
  getConstants(): {
6
13
  readonly GOOGLE_PLAY_SERVICES_SUPPORTED: boolean;
7
14
  readonly PASSWORD_SUPPORTED: boolean;
@@ -9,43 +16,87 @@ export interface Spec extends TurboModule {
9
16
  readonly APPLE_ID_SUPPORTED: boolean;
10
17
  readonly HYBRID_SUPPORTED: boolean;
11
18
  readonly PASSKEYS_SUPPORTED: boolean;
19
+ readonly OAUTH_REDIRECT_URI: string;
12
20
  };
13
21
  /**
14
- * Performs the google sign in.
15
- * @param androidAndIOSClientId
16
- * @param options
22
+ * iOS: GoogleSignIn `signIn` from the top most view controller. Android: Credential Manager
23
+ * Google ID / "Sign in with Google" option, then the Authorization API when `scopes` or
24
+ * `offlineAccess` are set. Resolves `GOOGLE_ID` or `CANCELLED`.
25
+ * @param androidAndIOSClientId - Web client id on Android, iOS client id on iOS. '' reads it from
26
+ * the app: iOS `GIDClientID`, then `CLIENT_ID` of GoogleService-Info.plist; Android the
27
+ * `com.oauthessentials.GOOGLE_WEB_CLIENT_ID` meta-data, then the `default_web_client_id` string
28
+ * (Firebase). Rejects `CONFIGURATION_ERROR` when it is missing or, on iOS, when its reversed URL
29
+ * scheme is not registered.
30
+ * @param options - GoogleSignInOptions, already normalized by `index.tsx`.
17
31
  */
18
32
  googleSignIn(androidAndIOSClientId: string, options: Object): Promise<Object>;
19
33
  /**
20
- * Sign ins with apple.
21
- * @param androidWebUrl
34
+ * iOS: GoogleSignIn `restorePreviousSignIn` (no UI). Android: Credential Manager filtered to
35
+ * authorized accounts with auto select, authorization without UI.
36
+ * Resolves `GOOGLE_ID` or `CANCELLED`, rejects `NO_SIGN_IN_AVAILABLE` when there is nothing to restore.
37
+ */
38
+ googleSilentSignIn(androidAndIOSClientId: string, options: Object): Promise<Object>;
39
+ /**
40
+ * iOS: GoogleSignIn `signOut`. Android: Credential Manager `clearCredentialState`.
41
+ * Resolves `true`. Does not emit events.
42
+ */
43
+ signOut(): Promise<boolean>;
44
+ /**
45
+ * iOS: native Apple ID request (`fullName`, `email`, `options.nonce`, `options.state`); resolves
46
+ * `APPLE_ID` or `CANCELLED`, `androidWebUrl` is ignored.
47
+ * Android: opens `androidWebUrl` in a Custom Tab and resolves `WEB_APPLE_ID` with the redirect
48
+ * url or `CANCELLED`; `options` is ignored.
49
+ * Unlike `appleSignIn` in `index.tsx`, it does not fill `email`/`fullName` from previous results.
50
+ */
51
+ appleSignIn(androidWebUrl: string | null, options: Object): Promise<Object>;
52
+ /**
53
+ * iOS: `ASAuthorizationAppleIDProvider.getCredentialState`, resolves `AUTHORIZED`, `REVOKED`,
54
+ * `TRANSFERRED` or `NOT_FOUND`. Android: always rejects `NOT_SUPPORTED_ERROR`.
22
55
  */
23
- appleSignIn(androidWebUrl?: string): Promise<Object>;
56
+ getAppleIdCredentialState(userId: string): Promise<string>;
24
57
  /**
25
- * Saves the username/password credential
26
- * @param username
27
- * @param password
58
+ * iOS: resolves `false` without doing anything. Android: Credential Manager
59
+ * `CreatePasswordRequest`, resolves `true` when saved and `false` on any error.
28
60
  */
29
61
  passwordSignIn(username: string, password: string): Promise<boolean>;
30
62
  /**
31
- * Gets the saved password.
63
+ * Shows the saved passwords. Resolves `PASSWORD`, or `CANCELLED` when there is none or the user
64
+ * dismisses it.
32
65
  */
33
66
  getPassword(): Promise<Object>;
34
67
  /**
35
- * Performs the called so "hybrid sign in"
36
- * @param googleClientId
37
- * @param options
68
+ * iOS: Apple ID + password request (`googleClientId` ignored). Android: Google ID + password
69
+ * Credential Manager request. Resolves the picked credential or `CANCELLED`.
38
70
  */
39
71
  hybridSignIn(googleClientId: string, options: Object): Promise<Object>;
40
72
  /**
41
- * Creates the passkey.
73
+ * Registers a passkey from `options.requestJson` (WebAuthn creation options).
74
+ * Resolves `PASSKEY` with the registration response JSON string in `data`, or `CANCELLED`.
42
75
  */
43
76
  createPassKey(options: Object): Promise<Object>;
44
77
  /**
45
- * Gets the passkey
46
- * @param options
78
+ * Asserts a passkey from `options.requestJson` (WebAuthn request options), with
79
+ * `options.mediation === 'autofill'` on iOS for QuickType bar AutoFill.
80
+ * Resolves `PASSKEY` with the authentication response JSON string in `data`, or `CANCELLED`.
47
81
  */
48
82
  getPassKey(options: Object): Promise<Object>;
83
+ /**
84
+ * iOS 16+: cancels a pending AutoFill `getPassKey` (which resolves `CANCELLED`) and resolves
85
+ * `true`, or resolves `false` when there is none. Android: resolves `false`.
86
+ */
87
+ cancelPassKeyAutoFill(): Promise<boolean>;
88
+ /**
89
+ * Resolves `{ codeVerifier, codeChallenge, state }`: a 32 byte random base64url verifier, its
90
+ * SHA-256 base64url challenge (PKCE S256) and a 16 byte random base64url state.
91
+ */
92
+ generatePkce(): Promise<Object>;
93
+ /**
94
+ * Opens `url` in `ASWebAuthenticationSession` (iOS, `options.callbackScheme`,
95
+ * `options.prefersEphemeralSession`) or a Custom Tab (Android, http/https only, `options`
96
+ * ignored). Resolves `{ type: 'REDIRECT', data: { url } }` with the redirect url, or `CANCELLED`.
97
+ * Does not emit events.
98
+ */
99
+ openAuthSession(url: string, options: Object): Promise<Object>;
49
100
  }
50
101
  declare const _default: Spec;
51
102
  export default _default;
@@ -57,4 +108,7 @@ type CredentialErrorEvent = {
57
108
  code: string;
58
109
  message: string;
59
110
  };
111
+ type AppleIdCredentialRevokedEvent = {
112
+ type: string;
113
+ };
60
114
  //# sourceMappingURL=NativeOauthEssentials.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"NativeOauthEssentials.d.ts","sourceRoot":"","sources":["../../../src/NativeOauthEssentials.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,KAAK,YAAY,EACjB,KAAK,WAAW,EAEjB,MAAM,cAAc,CAAC;AAEtB,MAAM,WAAW,IAAK,SAAQ,WAAW;IAEvC,QAAQ,CAAC,mBAAmB,EAAE,YAAY,CAAC,YAA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'./types';
2
+ /**
3
+ * Narrows an unknown error (e.g. in a `catch`) to an error rejected by this library, optionally
4
+ * with a specific code.
5
+ *
6
+ * ```ts
7
+ * try {
8
+ * await googleSignIn({ iosClientId, webClientId });
9
+ * } catch (e) {
10
+ * if (isCredentialError(e, CredentialError.BROWSER_UNAVAILABLE)) retryLater();
11
+ * else if (isCredentialError(e)) report(e.code, e.message);
12
+ * else throw e;
13
+ * }
14
+ * ```
15
+ */
16
+ export declare function isCredentialError<C extends CredentialErrorCode = CredentialErrorCode>(error: unknown, code?: C): error is OauthEssentialsError<C>;
17
+ export declare function createCredentialError<C extends CredentialErrorCode>(code: C, message: string, cause?: unknown): OauthEssentialsError<C>;
18
+ //# sourceMappingURL=errors.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"errors.d.ts","sourceRoot":"","sources":["../../../src/errors.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,mBAAmB,EACxB,KAAK,oBAAoB,EAC1B,MAAM,SAAS,CAAC;AAIjB;;;;;;;;;;;;;GAaG;AACH,wBAAgB,iBAAiB,CAC/B,CAAC,SAAS,mBAAmB,GAAG,mBAAmB,EACnD,KAAK,EAAE,OAAO,EAAE,IAAI,CAAC,EAAE,CAAC,GAAG,KAAK,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAS5D;AAED,wBAAgB,qBAAqB,CAAC,CAAC,SAAS,mBAAmB,EACjE,IAAI,EAAE,CAAC,EACP,OAAO,EAAE,MAAM,EACf,KAAK,CAAC,EAAE,OAAO,GACd,oBAAoB,CAAC,CAAC,CAAC,CASzB"}