react-native-oauth-essentials 1.0.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.
Files changed (41) hide show
  1. package/LICENSE +20 -0
  2. package/OauthEssentials.podspec +22 -0
  3. package/README.md +30 -0
  4. package/android/build.gradle +74 -0
  5. package/android/src/main/AndroidManifest.xml +22 -0
  6. package/android/src/main/java/com/oauthessentials/CredentialError.kt +7 -0
  7. package/android/src/main/java/com/oauthessentials/CredentialFactory.kt +114 -0
  8. package/android/src/main/java/com/oauthessentials/CustomTabsActivity.kt +133 -0
  9. package/android/src/main/java/com/oauthessentials/OauthEssentialsModule.kt +603 -0
  10. package/android/src/main/java/com/oauthessentials/OauthEssentialsPackage.kt +33 -0
  11. package/android/src/main/java/com/oauthessentials/RCTPromiseSettler.kt +60 -0
  12. package/ios/AppleIdRetriever.swift +61 -0
  13. package/ios/CredentialError.swift +6 -0
  14. package/ios/CredentialFactory.swift +133 -0
  15. package/ios/CredentialsType.swift +7 -0
  16. package/ios/GoogleIdRetriever.swift +83 -0
  17. package/ios/HybridRetriever.swift +64 -0
  18. package/ios/OauthEssentials.h +8 -0
  19. package/ios/OauthEssentials.mm +104 -0
  20. package/ios/OauthEssentialsModule.swift +210 -0
  21. package/ios/PasskeyRetriever.swift +226 -0
  22. package/ios/PasswordRetriever.swift +72 -0
  23. package/ios/RCTPromiseSettler.swift +28 -0
  24. package/lib/module/NativeOauthEssentials.js +5 -0
  25. package/lib/module/NativeOauthEssentials.js.map +1 -0
  26. package/lib/module/index.js +148 -0
  27. package/lib/module/index.js.map +1 -0
  28. package/lib/module/package.json +1 -0
  29. package/lib/module/types.js +23 -0
  30. package/lib/module/types.js.map +1 -0
  31. package/lib/typescript/package.json +1 -0
  32. package/lib/typescript/src/NativeOauthEssentials.d.ts +60 -0
  33. package/lib/typescript/src/NativeOauthEssentials.d.ts.map +1 -0
  34. package/lib/typescript/src/index.d.ts +78 -0
  35. package/lib/typescript/src/index.d.ts.map +1 -0
  36. package/lib/typescript/src/types.d.ts +71 -0
  37. package/lib/typescript/src/types.d.ts.map +1 -0
  38. package/package.json +156 -0
  39. package/src/NativeOauthEssentials.ts +75 -0
  40. package/src/index.tsx +199 -0
  41. package/src/types.ts +79 -0
package/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Lucas Alves
4
+ Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ of this software and associated documentation files (the "Software"), to deal
6
+ in the Software without restriction, including without limitation the rights
7
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ copies of the Software, and to permit persons to whom the Software is
9
+ furnished to do so, subject to the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be included in all
12
+ copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ SOFTWARE.
@@ -0,0 +1,22 @@
1
+ require "json"
2
+
3
+ package = JSON.parse(File.read(File.join(__dir__, "package.json")))
4
+
5
+ Pod::Spec.new do |s|
6
+ s.name = "OauthEssentials"
7
+ s.version = package["version"]
8
+ s.summary = package["description"]
9
+ s.homepage = package["homepage"]
10
+ s.license = package["license"]
11
+ s.authors = package["author"]
12
+
13
+ s.platforms = { :ios => min_ios_version_supported }
14
+ s.source = { :git => "https://github.com/lucaswitch/react-native-oauth-essentials.git", :tag => "#{s.version}" }
15
+
16
+ s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
+ s.private_header_files = "ios/**/*.h"
18
+
19
+ s.dependency "GoogleSignIn"
20
+
21
+ install_modules_dependencies(s)
22
+ end
package/README.md ADDED
@@ -0,0 +1,30 @@
1
+ # About
2
+
3
+ **React Native OAuth Essentials** is an essential OAuth solution for React Native apps. It provides **up-to-date Google
4
+ Sign-In, Apple Sign-In, and Password Sign-In**, delivering a **native sign-in experience** with a simple, promise-based
5
+ API. It's a must-have for every React Native app.
6
+
7
+ ## How to use it
8
+
9
+ [Installation](./installation.md)
10
+
11
+ [Usage](./usage)
12
+
13
+ ## Short history
14
+
15
+ I’ve always felt that React Native lacked a single library that handles OAuth end-to-end. Most React Native apps end up
16
+ downloading multiple libraries just to implement OAuth features. Each library feels different—they follow different
17
+ philosophies, have different implementations, and some are outdated.
18
+
19
+ Coming from native development, I wanted a library that provides all the OAuth features an app actually needs. That’s
20
+ why I created and launched it as “Essentials.” One big reason is that if you include Google OAuth in your app, Apple’s
21
+ App Store policies require you to provide Apple OAuth as well, or your app won’t be approved.
22
+
23
+ I was frustrated going through this process myself, and seeing how much time React Native developers spent trying to
24
+ deliver a “good enough” sign-in experience. So I thought—why not create one library that actually behaves and doesn’t
25
+ make me want to throw my laptop out the window?
26
+
27
+ ## Philosophy
28
+
29
+ Free forever, up-to-date features, and focused only on the essentials your mobile app really needs.
30
+
@@ -0,0 +1,74 @@
1
+ buildscript {
2
+ ext.OauthEssentials = [
3
+ kotlinVersion : "2.0.21",
4
+ minSdkVersion : 24,
5
+ compileSdkVersion: 36,
6
+ targetSdkVersion : 36
7
+ ]
8
+
9
+ ext.getExtOrDefault = { prop ->
10
+ if (rootProject.ext.has(prop)) {
11
+ return rootProject.ext.get(prop)
12
+ }
13
+
14
+ return OauthEssentials[prop]
15
+ }
16
+
17
+ repositories {
18
+ google()
19
+ mavenCentral()
20
+ }
21
+
22
+ dependencies {
23
+ classpath "com.android.tools.build:gradle:8.7.2"
24
+ // noinspection DifferentKotlinGradleVersion
25
+ classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:${getExtOrDefault('kotlinVersion')}"
26
+ }
27
+ }
28
+
29
+
30
+ apply plugin: "com.android.library"
31
+ apply plugin: "kotlin-android"
32
+
33
+ apply plugin: "com.facebook.react"
34
+
35
+ android {
36
+ namespace "com.oauthessentials"
37
+
38
+ compileSdkVersion getExtOrDefault("compileSdkVersion")
39
+
40
+ defaultConfig {
41
+ minSdkVersion getExtOrDefault("minSdkVersion")
42
+ targetSdkVersion getExtOrDefault("targetSdkVersion")
43
+ }
44
+
45
+ buildFeatures {
46
+ buildConfig true
47
+ }
48
+
49
+ buildTypes {
50
+ release {
51
+ minifyEnabled false
52
+ }
53
+ }
54
+
55
+ lint {
56
+ disable "GradleCompatible"
57
+ }
58
+
59
+ compileOptions {
60
+ sourceCompatibility JavaVersion.VERSION_1_8
61
+ targetCompatibility JavaVersion.VERSION_1_8
62
+ }
63
+ }
64
+
65
+ dependencies {
66
+ implementation "com.facebook.react:react-android"
67
+
68
+ // Needed oauth libraries
69
+ implementation 'androidx.browser:browser:1.9.0'
70
+ implementation 'androidx.credentials:credentials:1.5.0'
71
+ implementation("androidx.credentials:credentials-play-services-auth:1.6.0-rc01")
72
+ implementation 'com.google.android.libraries.identity.googleid:googleid:1.2.0'
73
+ implementation 'com.google.android.gms:play-services-auth:21.5.0'
74
+ }
@@ -0,0 +1,22 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+
3
+ <application>
4
+ <activity
5
+ android:name=".CustomTabsActivity"
6
+ android:exported="true"
7
+ android:launchMode="singleTask"
8
+ android:theme="@android:style/Theme.Translucent.NoTitleBar">
9
+ <intent-filter>
10
+ <action android:name="android.intent.action.VIEW" />
11
+
12
+ <category android:name="android.intent.category.DEFAULT" />
13
+ <category android:name="android.intent.category.BROWSABLE" />
14
+
15
+ <data
16
+ android:host="oauth"
17
+ android:path="/callback"
18
+ android:scheme="${applicationId}" />
19
+ </intent-filter>
20
+ </activity>
21
+ </application>
22
+ </manifest>
@@ -0,0 +1,7 @@
1
+ package com.oauthessentials
2
+
3
+ enum class CredentialError(val code: String) {
4
+ NO_ACTIVITY_ERROR("NO_ACTIVITY_ERROR"),
5
+ INVALID_RESULT_ERROR("INVALID_RESULT_ERROR"),
6
+ NOT_SUPPORTED_ERROR("NOT_SUPPORTED")
7
+ }
@@ -0,0 +1,114 @@
1
+ package com.oauthessentials
2
+
3
+ import android.net.Uri
4
+ import androidx.credentials.CreateCredentialResponse
5
+ import androidx.credentials.CreatePublicKeyCredentialResponse
6
+ import androidx.credentials.CustomCredential
7
+ import androidx.credentials.GetCredentialResponse
8
+ import androidx.credentials.PasswordCredential
9
+ import androidx.credentials.PublicKeyCredential
10
+ import com.facebook.react.bridge.Arguments
11
+ import com.facebook.react.bridge.WritableMap
12
+ import com.google.android.libraries.identity.googleid.GoogleIdTokenCredential
13
+
14
+ object CredentialFactory {
15
+
16
+ enum class CredentialsType(val code: String) {
17
+ GOOGLE_ID("GOOGLE_ID"),
18
+ PASSWORD("PASSWORD"),
19
+ APPLE_ID("APPLE_ID"),
20
+ WEB_APPLE_ID("WEB_APPLE_ID"),
21
+ CANCELLED("CANCELLED"),
22
+ PASSKEY("PASSKEY")
23
+ }
24
+
25
+
26
+ /**
27
+ * Creates from an uri.
28
+ */
29
+ fun fromUri(uri: Uri): WritableMap {
30
+ if (uri.query.isNullOrEmpty()) {
31
+ throw IllegalStateException("Cannot handle empty deep link query.")
32
+ }
33
+
34
+ val data = Arguments.createMap()
35
+ val queryParams = uri.queryParameterNames
36
+ for (key in queryParams) {
37
+ uri.getQueryParameter(key)?.let { value ->
38
+ data.putString(key, value)
39
+ }
40
+ }
41
+
42
+ val event = Arguments.createMap()
43
+ event.putString("type", CredentialsType.WEB_APPLE_ID.code)
44
+ event.putMap("data", data)
45
+ return event
46
+ }
47
+
48
+ /**
49
+ * Creates from a response.
50
+ */
51
+ fun fromCredentialResponse(result: GetCredentialResponse): WritableMap {
52
+ return Arguments.createMap().apply {
53
+ val data = Arguments.createMap()
54
+ when (val credential = result.credential) {
55
+ is PasswordCredential -> {
56
+ val username = credential.id
57
+ val password = credential.password
58
+
59
+ putString("type", CredentialsType.PASSWORD.code)
60
+ data.putString("username", username)
61
+ data.putString("password", password)
62
+ }
63
+
64
+ is CustomCredential -> when (credential.type) {
65
+ GoogleIdTokenCredential.TYPE_GOOGLE_ID_TOKEN_CREDENTIAL -> {
66
+ val googleCred = GoogleIdTokenCredential.createFrom(credential.data)
67
+
68
+ putString("type", CredentialsType.GOOGLE_ID.code)
69
+ data.putString("idToken", googleCred.idToken)
70
+ data.putString("id", googleCred.id)
71
+ data.putString("displayName", googleCred.displayName)
72
+ data.putString("givenName", googleCred.givenName)
73
+ data.putString("familyName", googleCred.familyName)
74
+ data.putString("profilePictureUri", googleCred.profilePictureUri?.toString())
75
+ data.putString("phoneNumber", googleCred.phoneNumber)
76
+ data.putBoolean("legacy", false)
77
+ }
78
+
79
+ else -> {
80
+ throw IllegalStateException("Invalid auth type.")
81
+ }
82
+ }
83
+
84
+ else -> {
85
+ throw IllegalStateException("Invalid auth type.")
86
+ }
87
+ }
88
+ putMap("data", data)
89
+ }
90
+ }
91
+
92
+ fun fromCancelled(): WritableMap {
93
+ return Arguments.createMap().apply {
94
+ putString("type", CredentialsType.CANCELLED.code)
95
+ putNull("data")
96
+ }
97
+ }
98
+
99
+ fun fromPublicKeyCredential(result: CreateCredentialResponse): WritableMap {
100
+ val response = result as CreatePublicKeyCredentialResponse
101
+ return Arguments.createMap().apply {
102
+ putString("type", CredentialsType.PASSKEY.code)
103
+ putString("data", response.registrationResponseJson)
104
+ }
105
+ }
106
+
107
+ fun fromPublicKeyCredential(result: GetCredentialResponse): WritableMap {
108
+ val credential = result.credential as PublicKeyCredential
109
+ return Arguments.createMap().apply {
110
+ putString("type", CredentialsType.PASSKEY.code)
111
+ putString("data", credential.authenticationResponseJson)
112
+ }
113
+ }
114
+ }
@@ -0,0 +1,133 @@
1
+ package com.oauthessentials
2
+
3
+ import android.app.Activity
4
+ import android.content.Intent
5
+ import android.content.Intent.FLAG_ACTIVITY_NO_HISTORY
6
+ import android.os.Bundle
7
+ import android.util.Log
8
+ import androidx.browser.customtabs.CustomTabsIntent
9
+ import com.oauthessentials.OauthEssentialsModule.Companion.DISPLAY_CUSTOM_TABS_INTENT
10
+ import com.oauthessentials.OauthEssentialsModule.Companion.LOG_TAG
11
+ import com.oauthessentials.OauthEssentialsModule.Companion.WEB_APPLE_DEEP_LINK_RECEIVED_INTENT
12
+ import com.oauthessentials.OauthEssentialsModule.Companion.WEB_APPLE_CANCELLED_INTENT
13
+
14
+ class CustomTabsActivity : Activity() {
15
+ private var deepLinkReceived = false
16
+ private var customTabLaunched = false
17
+ private var hasBeenPaused = false
18
+ private var resultProcessed = false
19
+
20
+ /**
21
+ * When the activity is created.
22
+ */
23
+ override fun onCreate(savedInstanceState: Bundle?) {
24
+ super.onCreate(savedInstanceState)
25
+ if (intent is Intent) {
26
+ when (intent.action) {
27
+ DISPLAY_CUSTOM_TABS_INTENT -> {
28
+ handleOnDisplayCustomTabsIntent(intent)
29
+ }
30
+
31
+ else -> {
32
+ handleOnDeepLinkIntent(intent)
33
+ }
34
+ }
35
+ }
36
+ }
37
+
38
+ /**
39
+ * When the activity resumes from background.
40
+ * This is called when the user closes the Custom Tab without completing authentication.
41
+ */
42
+ override fun onResume() {
43
+ super.onResume()
44
+ Log.d(LOG_TAG, "CustomTabsActivity resumed")
45
+
46
+ // Only check for cancellation if we've been paused (meaning the Custom Tab was shown)
47
+ // If we launched a custom tab but haven't received a deep link,
48
+ // it means the user closed the browser without completing auth
49
+ if (hasBeenPaused && customTabLaunched && !deepLinkReceived && !resultProcessed) {
50
+ Log.d(LOG_TAG, "CustomTabsActivity resumed without deep link, sending cancellation broadcast")
51
+ resultProcessed = true
52
+ sendBroadcast(
53
+ Intent(WEB_APPLE_CANCELLED_INTENT).apply {
54
+ setPackage(applicationContext.packageName)
55
+ }
56
+ )
57
+ // Return control to the previous activity
58
+ finish()
59
+ }
60
+ }
61
+
62
+ /**
63
+ * When the activity goes to background.
64
+ * This happens when the Custom Tab is displayed.
65
+ */
66
+ override fun onPause() {
67
+ super.onPause()
68
+ Log.d(LOG_TAG, "CustomTabsActivity paused")
69
+ if (customTabLaunched) {
70
+ hasBeenPaused = true
71
+ }
72
+ }
73
+
74
+ /**
75
+ * When the activity is destroyed.
76
+ */
77
+ override fun onDestroy() {
78
+ super.onDestroy()
79
+ Log.d(LOG_TAG, "CustomTabsActivity destroyed")
80
+ }
81
+
82
+ /**
83
+ * Whenever a new intent is received
84
+ */
85
+ override fun onNewIntent(intent: Intent?) {
86
+ super.onNewIntent(intent)
87
+ setIntent(intent)
88
+ if (intent is Intent) {
89
+ when (intent.action) {
90
+ DISPLAY_CUSTOM_TABS_INTENT -> {
91
+ handleOnDisplayCustomTabsIntent(intent)
92
+ }
93
+
94
+ else -> {
95
+ handleOnDeepLinkIntent(intent)
96
+ }
97
+ }
98
+ }
99
+ }
100
+
101
+ /**
102
+ * Handles the display custom tabs opening.
103
+ */
104
+ private fun handleOnDisplayCustomTabsIntent(intent: Intent) {
105
+ intent.data?.let { uri ->
106
+ Log.d(LOG_TAG, "Launching Custom Tab with URL: $uri")
107
+ customTabLaunched = true
108
+ val tabIntent =
109
+ CustomTabsIntent.Builder().setShowTitle(true).setUrlBarHidingEnabled(true).build()
110
+ tabIntent.intent.addFlags(FLAG_ACTIVITY_NO_HISTORY)
111
+ tabIntent.launchUrl(this, uri)
112
+ }
113
+ }
114
+
115
+ /**
116
+ * Handles the deep link intent.
117
+ */
118
+ private fun handleOnDeepLinkIntent(intent: Intent) {
119
+ Log.d(LOG_TAG, "Received new incoming intent")
120
+ intent.data?.let { uri ->
121
+ deepLinkReceived = true
122
+ resultProcessed = true
123
+ sendBroadcast(
124
+ Intent(WEB_APPLE_DEEP_LINK_RECEIVED_INTENT).apply {
125
+ setPackage(applicationContext.packageName)
126
+ putExtra("url", uri.toString())
127
+ }
128
+ )
129
+ // Return control to the previous activity
130
+ finish()
131
+ }
132
+ }
133
+ }