react-native-nitro-auth 0.5.4 → 0.5.6
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/README.md +82 -47
- package/android/proguard-rules.pro +7 -1
- package/android/src/main/AndroidManifest.xml +12 -0
- package/android/src/main/cpp/JniOnLoad.cpp +3 -1
- package/android/src/main/cpp/PlatformAuth+Android.cpp +271 -78
- package/android/src/main/java/com/auth/AuthAdapter.kt +293 -238
- package/android/src/main/java/com/auth/GoogleSignInActivity.kt +9 -5
- package/android/src/main/java/com/auth/NitroAuthModule.kt +8 -1
- package/cpp/HybridAuth.cpp +79 -64
- package/cpp/HybridAuth.hpp +9 -7
- package/cpp/JSONSerializer.hpp +3 -0
- package/ios/AuthAdapter.swift +226 -79
- package/ios/PlatformAuth+iOS.mm +10 -3
- package/lib/commonjs/Auth.web.js +50 -10
- package/lib/commonjs/Auth.web.js.map +1 -1
- package/lib/commonjs/index.js +23 -1
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/index.web.js +30 -12
- package/lib/commonjs/index.web.js.map +1 -1
- package/lib/commonjs/service.js +36 -9
- package/lib/commonjs/service.js.map +1 -1
- package/lib/commonjs/service.web.js +65 -13
- package/lib/commonjs/service.web.js.map +1 -1
- package/lib/commonjs/ui/social-button.js +19 -14
- package/lib/commonjs/ui/social-button.js.map +1 -1
- package/lib/commonjs/ui/social-button.web.js +16 -10
- package/lib/commonjs/ui/social-button.web.js.map +1 -1
- package/lib/commonjs/use-auth.js +22 -25
- package/lib/commonjs/use-auth.js.map +1 -1
- package/lib/commonjs/utils/auth-error.js +37 -0
- package/lib/commonjs/utils/auth-error.js.map +1 -0
- package/lib/commonjs/utils/logger.js +1 -0
- package/lib/commonjs/utils/logger.js.map +1 -1
- package/lib/module/Auth.web.js +50 -10
- package/lib/module/Auth.web.js.map +1 -1
- package/lib/module/global.d.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/index.web.js +2 -1
- package/lib/module/index.web.js.map +1 -1
- package/lib/module/service.js +36 -9
- package/lib/module/service.js.map +1 -1
- package/lib/module/service.web.js +65 -13
- package/lib/module/service.web.js.map +1 -1
- package/lib/module/ui/social-button.js +19 -14
- package/lib/module/ui/social-button.js.map +1 -1
- package/lib/module/ui/social-button.web.js +16 -10
- package/lib/module/ui/social-button.web.js.map +1 -1
- package/lib/module/use-auth.js +22 -25
- package/lib/module/use-auth.js.map +1 -1
- package/lib/module/utils/auth-error.js +30 -0
- package/lib/module/utils/auth-error.js.map +1 -0
- package/lib/module/utils/logger.js +1 -0
- package/lib/module/utils/logger.js.map +1 -1
- package/lib/typescript/commonjs/Auth.web.d.ts +5 -1
- package/lib/typescript/commonjs/Auth.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.d.ts +1 -0
- package/lib/typescript/commonjs/index.d.ts.map +1 -1
- package/lib/typescript/commonjs/index.web.d.ts +2 -1
- package/lib/typescript/commonjs/index.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/service.d.ts.map +1 -1
- package/lib/typescript/commonjs/service.web.d.ts +2 -18
- package/lib/typescript/commonjs/service.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/commonjs/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/commonjs/use-auth.d.ts +2 -1
- package/lib/typescript/commonjs/use-auth.d.ts.map +1 -1
- package/lib/typescript/commonjs/utils/auth-error.d.ts +16 -0
- package/lib/typescript/commonjs/utils/auth-error.d.ts.map +1 -0
- package/lib/typescript/commonjs/utils/logger.d.ts.map +1 -1
- package/lib/typescript/module/Auth.web.d.ts +5 -1
- package/lib/typescript/module/Auth.web.d.ts.map +1 -1
- package/lib/typescript/module/index.d.ts +1 -0
- package/lib/typescript/module/index.d.ts.map +1 -1
- package/lib/typescript/module/index.web.d.ts +2 -1
- package/lib/typescript/module/index.web.d.ts.map +1 -1
- package/lib/typescript/module/service.d.ts.map +1 -1
- package/lib/typescript/module/service.web.d.ts +2 -18
- package/lib/typescript/module/service.web.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.d.ts.map +1 -1
- package/lib/typescript/module/ui/social-button.web.d.ts.map +1 -1
- package/lib/typescript/module/use-auth.d.ts +2 -1
- package/lib/typescript/module/use-auth.d.ts.map +1 -1
- package/lib/typescript/module/utils/auth-error.d.ts +16 -0
- package/lib/typescript/module/utils/auth-error.d.ts.map +1 -0
- package/lib/typescript/module/utils/logger.d.ts.map +1 -1
- package/nitrogen/generated/android/NitroAuthOnLoad.cpp +22 -17
- package/nitrogen/generated/android/NitroAuthOnLoad.hpp +13 -4
- package/package.json +8 -10
- package/src/Auth.web.ts +77 -11
- package/src/global.d.ts +0 -11
- package/src/index.ts +5 -0
- package/src/index.web.ts +6 -1
- package/src/service.ts +37 -9
- package/src/service.web.ts +84 -15
- package/src/ui/social-button.tsx +21 -9
- package/src/ui/social-button.web.tsx +17 -4
- package/src/use-auth.ts +29 -67
- package/src/utils/auth-error.ts +49 -0
- package/src/utils/logger.ts +1 -0
|
@@ -2,4 +2,5 @@ export * from "./Auth.nitro";
|
|
|
2
2
|
export * from "./ui/social-button";
|
|
3
3
|
export { useAuth, type UseAuthReturn } from "./use-auth";
|
|
4
4
|
export { AuthService } from "./service";
|
|
5
|
+
export { AuthError, isAuthErrorCode, toAuthErrorCode, } from "./utils/auth-error";
|
|
5
6
|
//# sourceMappingURL=index.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,oBAAoB,CAAC;AACnC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,WAAW,CAAC;AACxC,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export * from "./Auth.nitro";
|
|
2
2
|
export * from "./ui/social-button.web";
|
|
3
|
-
export
|
|
3
|
+
export { useAuth, type UseAuthReturn } from "./use-auth";
|
|
4
4
|
export { AuthService } from "./service.web";
|
|
5
|
+
export { AuthError, isAuthErrorCode, toAuthErrorCode, } from "./utils/auth-error";
|
|
5
6
|
//# sourceMappingURL=index.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../src/index.web.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,
|
|
1
|
+
{"version":3,"file":"index.web.d.ts","sourceRoot":"","sources":["../../../src/index.web.ts"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,wBAAwB,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,KAAK,aAAa,EAAE,MAAM,YAAY,CAAC;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,eAAe,CAAC;AAC5C,OAAO,EACL,SAAS,EACT,eAAe,EACf,eAAe,GAChB,MAAM,oBAAoB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"service.d.ts","sourceRoot":"","sources":["../../../src/service.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAKtB,eAAO,MAAM,WAAW,EAAE,IA4FzB,CAAC"}
|
|
@@ -1,19 +1,3 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
currentUser: import("./Auth.nitro").AuthUser | undefined;
|
|
4
|
-
grantedScopes: string[];
|
|
5
|
-
hasPlayServices: boolean;
|
|
6
|
-
login: (provider: import("./Auth.nitro").AuthProvider, options?: import("./Auth.nitro").LoginOptions) => Promise<void>;
|
|
7
|
-
logout: () => void;
|
|
8
|
-
requestScopes: (scopes: string[]) => Promise<void>;
|
|
9
|
-
revokeScopes: (scopes: string[]) => Promise<void>;
|
|
10
|
-
getAccessToken: () => Promise<string | undefined>;
|
|
11
|
-
refreshToken: () => Promise<import("./Auth.nitro").AuthTokens>;
|
|
12
|
-
silentRestore: () => Promise<void>;
|
|
13
|
-
onAuthStateChanged: (callback: (user: import("./Auth.nitro").AuthUser | undefined) => void) => () => void;
|
|
14
|
-
onTokensRefreshed: (callback: (tokens: import("./Auth.nitro").AuthTokens) => void) => () => void;
|
|
15
|
-
setLoggingEnabled: (enabled: boolean) => void;
|
|
16
|
-
dispose: () => void;
|
|
17
|
-
equals: (other: unknown) => boolean;
|
|
18
|
-
};
|
|
1
|
+
import type { Auth } from "./Auth.nitro";
|
|
2
|
+
export declare const AuthService: Auth;
|
|
19
3
|
//# sourceMappingURL=service.web.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.web.d.ts","sourceRoot":"","sources":["../../../src/service.web.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"service.web.d.ts","sourceRoot":"","sources":["../../../src/service.web.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EACV,IAAI,EAKL,MAAM,cAAc,CAAC;AAItB,eAAO,MAAM,WAAW,EAAE,IA4FzB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"social-button.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"social-button.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAuFnB,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"social-button.web.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"social-button.web.d.ts","sourceRoot":"","sources":["../../../../src/ui/social-button.web.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAmB,MAAM,OAAO,CAAC;AACxC,OAAO,KAAK,EAAE,SAAS,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAUzD,OAAO,KAAK,EAAE,YAAY,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAE5D,MAAM,MAAM,mBAAmB,GAAG,SAAS,GAAG,SAAS,GAAG,OAAO,GAAG,OAAO,CAAC;AAE5E,MAAM,MAAM,iBAAiB,GAAG;IAC9B,QAAQ,EAAE,YAAY,CAAC;IACvB,OAAO,CAAC,EAAE,mBAAmB,CAAC;IAC9B,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,KAAK,CAAC,EAAE,SAAS,CAAC;IAClB,SAAS,CAAC,EAAE,SAAS,CAAC;IACtB,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,SAAS,CAAC,EAAE,CAAC,IAAI,EAAE,QAAQ,KAAK,IAAI,CAAC;IACrC,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,IAAI,CAAC;IACnC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CACtB,CAAC;AAqCF,eAAO,MAAM,YAAY,GAAI,+FAU1B,iBAAiB,sBAuFnB,CAAC"}
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import type { AuthUser, AuthProvider, LoginOptions, AuthTokens } from "./Auth.nitro";
|
|
2
|
+
import { AuthError } from "./utils/auth-error";
|
|
2
3
|
type AuthState = {
|
|
3
4
|
user: AuthUser | undefined;
|
|
4
5
|
scopes: string[];
|
|
5
6
|
loading: boolean;
|
|
6
|
-
error:
|
|
7
|
+
error: AuthError | undefined;
|
|
7
8
|
};
|
|
8
9
|
export type UseAuthReturn = AuthState & {
|
|
9
10
|
hasPlayServices: boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/use-auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;
|
|
1
|
+
{"version":3,"file":"use-auth.d.ts","sourceRoot":"","sources":["../../../src/use-auth.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EACV,QAAQ,EACR,YAAY,EACZ,YAAY,EACZ,UAAU,EACX,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,SAAS,EAAE,MAAM,oBAAoB,CAAC;AAE/C,KAAK,SAAS,GAAG;IACf,IAAI,EAAE,QAAQ,GAAG,SAAS,CAAC;IAC3B,MAAM,EAAE,MAAM,EAAE,CAAC;IACjB,OAAO,EAAE,OAAO,CAAC;IACjB,KAAK,EAAE,SAAS,GAAG,SAAS,CAAC;CAC9B,CAAC;AAYF,MAAM,MAAM,aAAa,GAAG,SAAS,GAAG;IACtC,eAAe,EAAE,OAAO,CAAC;IACzB,KAAK,EAAE,CAAC,QAAQ,EAAE,YAAY,EAAE,OAAO,CAAC,EAAE,YAAY,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACzE,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,aAAa,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IACnD,YAAY,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAClD,cAAc,EAAE,MAAM,OAAO,CAAC,MAAM,GAAG,SAAS,CAAC,CAAC;IAClD,YAAY,EAAE,MAAM,OAAO,CAAC,UAAU,CAAC,CAAC;IACxC,aAAa,EAAE,MAAM,OAAO,CAAC,IAAI,CAAC,CAAC;CACpC,CAAC;AAEF,wBAAgB,OAAO,IAAI,aAAa,CAgKvC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { AuthErrorCode } from "../Auth.nitro";
|
|
2
|
+
export declare function isAuthErrorCode(value: string): value is AuthErrorCode;
|
|
3
|
+
export declare function toAuthErrorCode(raw: string): AuthErrorCode;
|
|
4
|
+
/**
|
|
5
|
+
* Typed error thrown by all AuthService operations.
|
|
6
|
+
*
|
|
7
|
+
* - `code` — always a valid `AuthErrorCode`, safe to switch on
|
|
8
|
+
* - `underlyingMessage` — the raw platform message when it differs from `code`
|
|
9
|
+
*/
|
|
10
|
+
export declare class AuthError extends Error {
|
|
11
|
+
readonly code: AuthErrorCode;
|
|
12
|
+
readonly underlyingMessage: string | undefined;
|
|
13
|
+
constructor(raw: unknown);
|
|
14
|
+
static from(e: unknown): AuthError;
|
|
15
|
+
}
|
|
16
|
+
//# sourceMappingURL=auth-error.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"auth-error.d.ts","sourceRoot":"","sources":["../../../../src/utils/auth-error.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAkBnD,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAErE;AAED,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,aAAa,CAE1D;AAED;;;;;GAKG;AACH,qBAAa,SAAU,SAAQ,KAAK;IAClC,QAAQ,CAAC,IAAI,EAAE,aAAa,CAAC;IAC7B,QAAQ,CAAC,iBAAiB,EAAE,MAAM,GAAG,SAAS,CAAC;gBAEnC,GAAG,EAAE,OAAO;IASxB,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,OAAO,GAAG,SAAS;CAGnC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/utils/logger.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"logger.d.ts","sourceRoot":"","sources":["../../../../src/utils/logger.ts"],"names":[],"mappings":"AAGA,eAAO,MAAM,MAAM;sBACC,OAAO,GAAG,IAAI;mBAGjB,OAAO,EAAE;oBAGR,OAAO,EAAE;qBAGR,OAAO,EAAE;qBAGT,OAAO,EAAE;CAG3B,CAAC"}
|
|
@@ -20,25 +20,30 @@
|
|
|
20
20
|
namespace margelo::nitro::NitroAuth {
|
|
21
21
|
|
|
22
22
|
int initialize(JavaVM* vm) {
|
|
23
|
+
return facebook::jni::initialize(vm, []() {
|
|
24
|
+
::margelo::nitro::NitroAuth::registerAllNatives();
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
void registerAllNatives() {
|
|
23
31
|
using namespace margelo::nitro;
|
|
24
32
|
using namespace margelo::nitro::NitroAuth;
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
});
|
|
33
|
+
|
|
34
|
+
// Register native JNI methods
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
// Register Nitro Hybrid Objects
|
|
38
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
39
|
+
"Auth",
|
|
40
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
41
|
+
static_assert(std::is_default_constructible_v<HybridAuth>,
|
|
42
|
+
"The HybridObject \"HybridAuth\" is not default-constructible! "
|
|
43
|
+
"Create a public constructor that takes zero arguments to be able to autolink this HybridObject.");
|
|
44
|
+
return std::make_shared<HybridAuth>();
|
|
45
|
+
}
|
|
46
|
+
);
|
|
42
47
|
}
|
|
43
48
|
|
|
44
49
|
} // namespace margelo::nitro::NitroAuth
|
|
@@ -6,20 +6,29 @@
|
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
9
10
|
#include <NitroModules/NitroDefines.hpp>
|
|
10
11
|
|
|
11
12
|
namespace margelo::nitro::NitroAuth {
|
|
12
13
|
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`)
|
|
18
|
+
* Register the native (C++) part of NitroAuth, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
16
21
|
* Example:
|
|
17
22
|
* ```cpp (cpp-adapter.cpp)
|
|
18
23
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
-
* return
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all NitroAuth HybridObjects
|
|
26
|
+
* margelo::nitro::NitroAuth::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
20
29
|
* }
|
|
21
30
|
* ```
|
|
22
31
|
*/
|
|
23
|
-
|
|
32
|
+
void registerAllNatives();
|
|
24
33
|
|
|
25
34
|
} // namespace margelo::nitro::NitroAuth
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-auth",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.6",
|
|
4
4
|
"description": "High-performance authentication library for React Native with Google Sign-In, Apple Sign-In, and Microsoft Sign-In support, powered by Nitro Modules (JSI)",
|
|
5
5
|
"main": "lib/commonjs/index.js",
|
|
6
6
|
"module": "lib/module/index.js",
|
|
@@ -35,9 +35,7 @@
|
|
|
35
35
|
"codegen": "nitrogen --logLevel=\"debug\"",
|
|
36
36
|
"lint": "eslint .",
|
|
37
37
|
"typecheck": "tsc --noEmit",
|
|
38
|
-
|
|
39
|
-
"format:check": "prettier --check .",
|
|
40
|
-
"test": "jest",
|
|
38
|
+
"test": "jest",
|
|
41
39
|
"test:coverage": "jest --coverage",
|
|
42
40
|
"test:cpp": "node scripts/test-cpp.js",
|
|
43
41
|
"prepublishOnly": "bun run clean && bun run build",
|
|
@@ -81,21 +79,21 @@
|
|
|
81
79
|
"access": "public"
|
|
82
80
|
},
|
|
83
81
|
"devDependencies": {
|
|
84
|
-
"@expo/config-plugins": "^
|
|
85
|
-
"@react-native/babel-preset": "^0.
|
|
82
|
+
"@expo/config-plugins": "^55.0.6",
|
|
83
|
+
"@react-native/babel-preset": "^0.83.0",
|
|
86
84
|
"@testing-library/react": "^16.3.2",
|
|
87
85
|
"@types/node": "^22.19.11",
|
|
88
86
|
"jest-environment-jsdom": "^29.7.0",
|
|
89
|
-
"react": "19.
|
|
90
|
-
"react-native": "0.
|
|
91
|
-
"react-native-nitro-modules": "^0.
|
|
87
|
+
"react": "19.2.0",
|
|
88
|
+
"react-native": "0.83.2",
|
|
89
|
+
"react-native-nitro-modules": "^0.35.0",
|
|
92
90
|
"react-native-web": "^0.21.2",
|
|
93
91
|
"typescript": "^5.9.3"
|
|
94
92
|
},
|
|
95
93
|
"peerDependencies": {
|
|
96
94
|
"react": "*",
|
|
97
95
|
"react-native": ">=0.75.0",
|
|
98
|
-
"react-native-nitro-modules": ">=0.
|
|
96
|
+
"react-native-nitro-modules": ">=0.35.0"
|
|
99
97
|
},
|
|
100
98
|
"react-native-builder-bob": {
|
|
101
99
|
"source": "src",
|
package/src/Auth.web.ts
CHANGED
|
@@ -24,6 +24,7 @@ const WEB_STORAGE_MODES = new Set([
|
|
|
24
24
|
STORAGE_MODE_MEMORY,
|
|
25
25
|
] as const);
|
|
26
26
|
const inMemoryWebStorage = new Map<string, string>();
|
|
27
|
+
let _appleSdkLoadPromise: Promise<void> | undefined;
|
|
27
28
|
|
|
28
29
|
type WebStorageDriver = {
|
|
29
30
|
save(key: string, value: string): void;
|
|
@@ -152,6 +153,7 @@ const parseAuthWebExtraConfig = (value: unknown): AuthWebExtraConfig => {
|
|
|
152
153
|
|
|
153
154
|
const getConfig = (): AuthWebExtraConfig => {
|
|
154
155
|
try {
|
|
156
|
+
// eslint-disable-next-line @typescript-eslint/no-require-imports
|
|
155
157
|
const Constants = require("expo-constants").default;
|
|
156
158
|
return parseAuthWebExtraConfig(Constants.expoConfig?.extra);
|
|
157
159
|
} catch (error) {
|
|
@@ -175,7 +177,8 @@ class AuthWeb implements Auth {
|
|
|
175
177
|
private _browserStorageResolved = false;
|
|
176
178
|
private _browserStorageCache: Storage | undefined;
|
|
177
179
|
private _refreshPromise: Promise<AuthTokens> | undefined;
|
|
178
|
-
private
|
|
180
|
+
private _pendingGoogleNonce: string | undefined;
|
|
181
|
+
private _loginInFlight: boolean = false;
|
|
179
182
|
|
|
180
183
|
constructor() {
|
|
181
184
|
this._config = getConfig();
|
|
@@ -303,6 +306,7 @@ class AuthWeb implements Auth {
|
|
|
303
306
|
const storage = this.getBrowserStorage();
|
|
304
307
|
if (storage) {
|
|
305
308
|
storage.removeItem(key);
|
|
309
|
+
return;
|
|
306
310
|
}
|
|
307
311
|
inMemoryWebStorage.delete(key);
|
|
308
312
|
}
|
|
@@ -539,7 +543,7 @@ class AuthWeb implements Auth {
|
|
|
539
543
|
const refreshToken = this.loadRefreshToken();
|
|
540
544
|
|
|
541
545
|
if (!refreshToken) {
|
|
542
|
-
throw new
|
|
546
|
+
throw new AuthWebError("refresh_failed", "No refresh token available");
|
|
543
547
|
}
|
|
544
548
|
|
|
545
549
|
const clientId = this._config.microsoftClientId;
|
|
@@ -645,13 +649,27 @@ class AuthWeb implements Auth {
|
|
|
645
649
|
|
|
646
650
|
if (msg.includes("cancel") || msg.includes("popup_closed")) {
|
|
647
651
|
mappedMsg = "cancelled";
|
|
652
|
+
} else if (msg.includes("access_denied")) {
|
|
653
|
+
mappedMsg = "cancelled";
|
|
648
654
|
} else if (msg.includes("timeout")) {
|
|
649
655
|
mappedMsg = "timeout";
|
|
650
656
|
} else if (msg.includes("popup blocked")) {
|
|
651
657
|
mappedMsg = "popup_blocked";
|
|
652
|
-
} else if (
|
|
658
|
+
} else if (
|
|
659
|
+
msg.includes("network") ||
|
|
660
|
+
msg.includes("server_error") ||
|
|
661
|
+
msg.includes("temporarily_unavailable")
|
|
662
|
+
) {
|
|
653
663
|
mappedMsg = "network_error";
|
|
654
|
-
} else if (msg.includes("
|
|
664
|
+
} else if (msg.includes("invalid_grant") || msg.includes("invalid_token")) {
|
|
665
|
+
mappedMsg = "refresh_failed";
|
|
666
|
+
} else if (
|
|
667
|
+
msg.includes("invalid_scope") ||
|
|
668
|
+
msg.includes("unauthorized_client") ||
|
|
669
|
+
msg.includes("invalid_client") ||
|
|
670
|
+
msg.includes("client id") ||
|
|
671
|
+
msg.includes("config")
|
|
672
|
+
) {
|
|
655
673
|
mappedMsg = "configuration_error";
|
|
656
674
|
}
|
|
657
675
|
|
|
@@ -746,6 +764,24 @@ class AuthWeb implements Auth {
|
|
|
746
764
|
private async loginGoogle(
|
|
747
765
|
scopes: string[],
|
|
748
766
|
loginHint?: string,
|
|
767
|
+
): Promise<void> {
|
|
768
|
+
if (this._loginInFlight) {
|
|
769
|
+
throw new AuthWebError(
|
|
770
|
+
"cancelled",
|
|
771
|
+
"Another login is already in progress",
|
|
772
|
+
);
|
|
773
|
+
}
|
|
774
|
+
this._loginInFlight = true;
|
|
775
|
+
try {
|
|
776
|
+
await this._loginGoogleInner(scopes, loginHint);
|
|
777
|
+
} finally {
|
|
778
|
+
this._loginInFlight = false;
|
|
779
|
+
}
|
|
780
|
+
}
|
|
781
|
+
|
|
782
|
+
private async _loginGoogleInner(
|
|
783
|
+
scopes: string[],
|
|
784
|
+
loginHint?: string,
|
|
749
785
|
): Promise<void> {
|
|
750
786
|
const clientId = this._config.googleWebClientId;
|
|
751
787
|
|
|
@@ -755,6 +791,8 @@ class AuthWeb implements Auth {
|
|
|
755
791
|
);
|
|
756
792
|
}
|
|
757
793
|
|
|
794
|
+
const nonce = crypto.randomUUID();
|
|
795
|
+
this._pendingGoogleNonce = nonce;
|
|
758
796
|
return new Promise((resolve, reject) => {
|
|
759
797
|
const redirectUri = window.location.origin;
|
|
760
798
|
const authUrl = new URL("https://accounts.google.com/o/oauth2/v2/auth");
|
|
@@ -762,7 +800,7 @@ class AuthWeb implements Auth {
|
|
|
762
800
|
authUrl.searchParams.set("redirect_uri", redirectUri);
|
|
763
801
|
authUrl.searchParams.set("response_type", "id_token token code");
|
|
764
802
|
authUrl.searchParams.set("scope", scopes.join(" "));
|
|
765
|
-
authUrl.searchParams.set("nonce",
|
|
803
|
+
authUrl.searchParams.set("nonce", nonce);
|
|
766
804
|
authUrl.searchParams.set("access_type", "offline");
|
|
767
805
|
authUrl.searchParams.set("prompt", "consent");
|
|
768
806
|
|
|
@@ -798,6 +836,13 @@ class AuthWeb implements Auth {
|
|
|
798
836
|
throw new Error("No id_token in response");
|
|
799
837
|
}
|
|
800
838
|
|
|
839
|
+
const decoded = this.parseJwtPayload(idToken);
|
|
840
|
+
if (decoded["nonce"] !== this._pendingGoogleNonce) {
|
|
841
|
+
this._pendingGoogleNonce = undefined;
|
|
842
|
+
throw new Error("Nonce mismatch - possible replay attack");
|
|
843
|
+
}
|
|
844
|
+
this._pendingGoogleNonce = undefined;
|
|
845
|
+
|
|
801
846
|
this._grantedScopes = scopes;
|
|
802
847
|
this.saveValue(SCOPES_KEY, JSON.stringify(scopes));
|
|
803
848
|
|
|
@@ -842,6 +887,26 @@ class AuthWeb implements Auth {
|
|
|
842
887
|
loginHint?: string,
|
|
843
888
|
tenant?: string,
|
|
844
889
|
prompt?: string,
|
|
890
|
+
): Promise<void> {
|
|
891
|
+
if (this._loginInFlight) {
|
|
892
|
+
throw new AuthWebError(
|
|
893
|
+
"cancelled",
|
|
894
|
+
"Another login is already in progress",
|
|
895
|
+
);
|
|
896
|
+
}
|
|
897
|
+
this._loginInFlight = true;
|
|
898
|
+
try {
|
|
899
|
+
await this._loginMicrosoftInner(scopes, loginHint, tenant, prompt);
|
|
900
|
+
} finally {
|
|
901
|
+
this._loginInFlight = false;
|
|
902
|
+
}
|
|
903
|
+
}
|
|
904
|
+
|
|
905
|
+
private async _loginMicrosoftInner(
|
|
906
|
+
scopes: string[],
|
|
907
|
+
loginHint?: string,
|
|
908
|
+
tenant?: string,
|
|
909
|
+
prompt?: string,
|
|
845
910
|
): Promise<void> {
|
|
846
911
|
const clientId = this._config.microsoftClientId;
|
|
847
912
|
|
|
@@ -1074,11 +1139,11 @@ class AuthWeb implements Auth {
|
|
|
1074
1139
|
return;
|
|
1075
1140
|
}
|
|
1076
1141
|
|
|
1077
|
-
if (
|
|
1078
|
-
return
|
|
1142
|
+
if (_appleSdkLoadPromise) {
|
|
1143
|
+
return _appleSdkLoadPromise;
|
|
1079
1144
|
}
|
|
1080
1145
|
|
|
1081
|
-
|
|
1146
|
+
_appleSdkLoadPromise = new Promise<void>((resolve, reject) => {
|
|
1082
1147
|
const scriptId = "nitro-auth-apple-sdk";
|
|
1083
1148
|
const existingScript = document.getElementById(
|
|
1084
1149
|
scriptId,
|
|
@@ -1102,7 +1167,7 @@ class AuthWeb implements Auth {
|
|
|
1102
1167
|
existingScript.addEventListener(
|
|
1103
1168
|
"error",
|
|
1104
1169
|
() => {
|
|
1105
|
-
|
|
1170
|
+
_appleSdkLoadPromise = undefined;
|
|
1106
1171
|
reject(new Error("Failed to load Apple SDK"));
|
|
1107
1172
|
},
|
|
1108
1173
|
{ once: true },
|
|
@@ -1119,13 +1184,13 @@ class AuthWeb implements Auth {
|
|
|
1119
1184
|
resolve();
|
|
1120
1185
|
};
|
|
1121
1186
|
script.onerror = () => {
|
|
1122
|
-
|
|
1187
|
+
_appleSdkLoadPromise = undefined;
|
|
1123
1188
|
reject(new Error("Failed to load Apple SDK"));
|
|
1124
1189
|
};
|
|
1125
1190
|
document.head.appendChild(script);
|
|
1126
1191
|
});
|
|
1127
1192
|
|
|
1128
|
-
return
|
|
1193
|
+
return _appleSdkLoadPromise;
|
|
1129
1194
|
}
|
|
1130
1195
|
|
|
1131
1196
|
private async loginApple(): Promise<void> {
|
|
@@ -1199,6 +1264,7 @@ class AuthWeb implements Auth {
|
|
|
1199
1264
|
logger.setEnabled(enabled);
|
|
1200
1265
|
}
|
|
1201
1266
|
|
|
1267
|
+
/** @internal Reserved for future use — not part of the public API */
|
|
1202
1268
|
setWebStorageAdapter(adapter: JSStorageAdapter | undefined): void {
|
|
1203
1269
|
this._storageAdapter = adapter
|
|
1204
1270
|
? this.createWebStorageDriver(adapter)
|
package/src/global.d.ts
CHANGED
|
@@ -1,16 +1,5 @@
|
|
|
1
1
|
declare global {
|
|
2
2
|
interface Window {
|
|
3
|
-
google?: {
|
|
4
|
-
accounts: {
|
|
5
|
-
id: {
|
|
6
|
-
initialize: (config: {
|
|
7
|
-
client_id: string;
|
|
8
|
-
callback: (response: { credential: string }) => void;
|
|
9
|
-
}) => void;
|
|
10
|
-
prompt: () => void;
|
|
11
|
-
};
|
|
12
|
-
};
|
|
13
|
-
};
|
|
14
3
|
AppleID?: {
|
|
15
4
|
auth: {
|
|
16
5
|
init: (config: {
|
package/src/index.ts
CHANGED
package/src/index.web.ts
CHANGED
|
@@ -1,4 +1,9 @@
|
|
|
1
1
|
export * from "./Auth.nitro";
|
|
2
2
|
export * from "./ui/social-button.web";
|
|
3
|
-
export
|
|
3
|
+
export { useAuth, type UseAuthReturn } from "./use-auth";
|
|
4
4
|
export { AuthService } from "./service.web";
|
|
5
|
+
export {
|
|
6
|
+
AuthError,
|
|
7
|
+
isAuthErrorCode,
|
|
8
|
+
toAuthErrorCode,
|
|
9
|
+
} from "./utils/auth-error";
|
package/src/service.ts
CHANGED
|
@@ -6,8 +6,10 @@ import type {
|
|
|
6
6
|
LoginOptions,
|
|
7
7
|
AuthUser,
|
|
8
8
|
} from "./Auth.nitro";
|
|
9
|
+
import { AuthError } from "./utils/auth-error";
|
|
9
10
|
|
|
10
11
|
const nitroAuth = NitroModules.createHybridObject<Auth>("Auth");
|
|
12
|
+
|
|
11
13
|
export const AuthService: Auth = {
|
|
12
14
|
get name() {
|
|
13
15
|
return nitroAuth.name;
|
|
@@ -26,23 +28,46 @@ export const AuthService: Auth = {
|
|
|
26
28
|
},
|
|
27
29
|
|
|
28
30
|
async login(provider: AuthProvider, options?: LoginOptions) {
|
|
29
|
-
|
|
31
|
+
try {
|
|
32
|
+
await nitroAuth.login(provider, options);
|
|
33
|
+
return;
|
|
34
|
+
} catch (e) {
|
|
35
|
+
throw AuthError.from(e);
|
|
36
|
+
}
|
|
30
37
|
},
|
|
31
38
|
|
|
32
39
|
async requestScopes(scopes: string[]) {
|
|
33
|
-
|
|
40
|
+
try {
|
|
41
|
+
await nitroAuth.requestScopes(scopes);
|
|
42
|
+
return;
|
|
43
|
+
} catch (e) {
|
|
44
|
+
throw AuthError.from(e);
|
|
45
|
+
}
|
|
34
46
|
},
|
|
35
47
|
|
|
36
48
|
async revokeScopes(scopes: string[]) {
|
|
37
|
-
|
|
49
|
+
try {
|
|
50
|
+
await nitroAuth.revokeScopes(scopes);
|
|
51
|
+
return;
|
|
52
|
+
} catch (e) {
|
|
53
|
+
throw AuthError.from(e);
|
|
54
|
+
}
|
|
38
55
|
},
|
|
39
56
|
|
|
40
57
|
async getAccessToken() {
|
|
41
|
-
|
|
58
|
+
try {
|
|
59
|
+
return await nitroAuth.getAccessToken();
|
|
60
|
+
} catch (e) {
|
|
61
|
+
throw AuthError.from(e);
|
|
62
|
+
}
|
|
42
63
|
},
|
|
43
64
|
|
|
44
65
|
async refreshToken() {
|
|
45
|
-
|
|
66
|
+
try {
|
|
67
|
+
return await nitroAuth.refreshToken();
|
|
68
|
+
} catch (e) {
|
|
69
|
+
throw AuthError.from(e);
|
|
70
|
+
}
|
|
46
71
|
},
|
|
47
72
|
|
|
48
73
|
logout() {
|
|
@@ -50,13 +75,16 @@ export const AuthService: Auth = {
|
|
|
50
75
|
},
|
|
51
76
|
|
|
52
77
|
async silentRestore() {
|
|
53
|
-
|
|
78
|
+
try {
|
|
79
|
+
await nitroAuth.silentRestore();
|
|
80
|
+
return;
|
|
81
|
+
} catch (e) {
|
|
82
|
+
throw AuthError.from(e);
|
|
83
|
+
}
|
|
54
84
|
},
|
|
55
85
|
|
|
56
86
|
onAuthStateChanged(callback: (user: AuthUser | undefined) => void) {
|
|
57
|
-
return nitroAuth.onAuthStateChanged(
|
|
58
|
-
callback(user);
|
|
59
|
-
});
|
|
87
|
+
return nitroAuth.onAuthStateChanged(callback);
|
|
60
88
|
},
|
|
61
89
|
|
|
62
90
|
onTokensRefreshed(callback: (tokens: AuthTokens) => void) {
|