react-native-oauth-essentials 1.0.12 → 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 +445 -187
  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 -2
  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 -1
@@ -3,5 +3,8 @@ package com.oauthessentials
3
3
  enum class CredentialError(val code: String) {
4
4
  NO_ACTIVITY_ERROR("NO_ACTIVITY_ERROR"),
5
5
  INVALID_RESULT_ERROR("INVALID_RESULT_ERROR"),
6
- NOT_SUPPORTED_ERROR("NOT_SUPPORTED")
6
+ NOT_SUPPORTED_ERROR("NOT_SUPPORTED_ERROR"),
7
+ NO_SIGN_IN_AVAILABLE("NO_SIGN_IN_AVAILABLE"),
8
+ BROWSER_UNAVAILABLE("BROWSER_UNAVAILABLE"),
9
+ CONFIGURATION_ERROR("CONFIGURATION_ERROR")
7
10
  }
@@ -9,6 +9,7 @@ import androidx.credentials.PasswordCredential
9
9
  import androidx.credentials.PublicKeyCredential
10
10
  import com.facebook.react.bridge.Arguments
11
11
  import com.facebook.react.bridge.WritableMap
12
+ import com.google.android.gms.auth.api.identity.AuthorizationResult
12
13
  import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
13
14
 
14
15
  object CredentialFactory {
@@ -19,7 +20,8 @@ object CredentialFactory {
19
20
  APPLE_ID("APPLE_ID"),
20
21
  WEB_APPLE_ID("WEB_APPLE_ID"),
21
22
  CANCELLED("CANCELLED"),
22
- PASSKEY("PASSKEY")
23
+ PASSKEY("PASSKEY"),
24
+ REDIRECT("REDIRECT")
23
25
  }
24
26
 
25
27
 
@@ -48,7 +50,10 @@ object CredentialFactory {
48
50
  /**
49
51
  * Creates from a response.
50
52
  */
51
- fun fromCredentialResponse(result: GetCredentialResponse): WritableMap {
53
+ fun fromCredentialResponse(
54
+ result: GetCredentialResponse,
55
+ authorization: AuthorizationResult? = null
56
+ ): WritableMap {
52
57
  return Arguments.createMap().apply {
53
58
  val data = Arguments.createMap()
54
59
  when (val credential = result.credential) {
@@ -73,7 +78,15 @@ object CredentialFactory {
73
78
  data.putString("familyName", googleCred.familyName)
74
79
  data.putString("profilePictureUri", googleCred.profilePictureUri?.toString())
75
80
  data.putString("phoneNumber", googleCred.phoneNumber)
81
+ data.putString("email", googleCred.id)
76
82
  data.putBoolean("legacy", false)
83
+ data.putString("accessToken", authorization?.accessToken)
84
+ data.putString("serverAuthCode", authorization?.serverAuthCode)
85
+ if (authorization != null) {
86
+ data.putArray("grantedScopes", Arguments.fromList(authorization.grantedScopes))
87
+ } else {
88
+ data.putNull("grantedScopes")
89
+ }
77
90
  }
78
91
 
79
92
  else -> {
@@ -89,6 +102,15 @@ object CredentialFactory {
89
102
  }
90
103
  }
91
104
 
105
+ fun fromRedirect(url: String): WritableMap {
106
+ return Arguments.createMap().apply {
107
+ putString("type", CredentialsType.REDIRECT.code)
108
+ putMap("data", Arguments.createMap().apply {
109
+ putString("url", url)
110
+ })
111
+ }
112
+ }
113
+
92
114
  fun fromCancelled(): WritableMap {
93
115
  return Arguments.createMap().apply {
94
116
  putString("type", CredentialsType.CANCELLED.code)
@@ -1,6 +1,7 @@
1
1
  package com.oauthessentials
2
2
 
3
3
  import android.app.Activity
4
+ import android.content.ActivityNotFoundException
4
5
  import android.content.Intent
5
6
  import android.content.Intent.FLAG_ACTIVITY_NO_HISTORY
6
7
  import android.os.Bundle
@@ -10,6 +11,7 @@ import com.oauthessentials.OauthEssentialsModule.Companion.DISPLAY_CUSTOM_TABS_I
10
11
  import com.oauthessentials.OauthEssentialsModule.Companion.LOG_TAG
11
12
  import com.oauthessentials.OauthEssentialsModule.Companion.WEB_APPLE_DEEP_LINK_RECEIVED_INTENT
12
13
  import com.oauthessentials.OauthEssentialsModule.Companion.WEB_APPLE_CANCELLED_INTENT
14
+ import com.oauthessentials.OauthEssentialsModule.Companion.WEB_BROWSER_UNAVAILABLE_INTENT
13
15
 
14
16
  class CustomTabsActivity : Activity() {
15
17
  private var deepLinkReceived = false
@@ -108,7 +110,18 @@ class CustomTabsActivity : Activity() {
108
110
  val tabIntent =
109
111
  CustomTabsIntent.Builder().setShowTitle(true).setUrlBarHidingEnabled(true).build()
110
112
  tabIntent.intent.addFlags(FLAG_ACTIVITY_NO_HISTORY)
111
- tabIntent.launchUrl(this, uri)
113
+ try {
114
+ tabIntent.launchUrl(this, uri)
115
+ } catch (e: ActivityNotFoundException) {
116
+ Log.e(LOG_TAG, "No browser available to open $uri")
117
+ resultProcessed = true
118
+ sendBroadcast(
119
+ Intent(WEB_BROWSER_UNAVAILABLE_INTENT).apply {
120
+ setPackage(applicationContext.packageName)
121
+ }
122
+ )
123
+ finish()
124
+ }
112
125
  }
113
126
  }
114
127