capacitor-auth-manager 0.0.1 → 1.0.0

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 (62) hide show
  1. package/CapacitorAuthManager.podspec +36 -0
  2. package/LICENSE +1 -1
  3. package/Readme.md +577 -20
  4. package/android/build.gradle +79 -0
  5. package/android/gradle.properties +25 -0
  6. package/android/proguard-rules.pro +38 -0
  7. package/android/settings.gradle +2 -0
  8. package/android/src/main/AndroidManifest.xml +11 -0
  9. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthLogger.java +117 -0
  10. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/AuthStorage.java +124 -0
  11. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/BaseAuthProvider.java +16 -0
  12. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManager.java +385 -0
  13. package/android/src/main/java/com/aoneahsan/capacitor_auth_manager/CapacitorAuthManagerPlugin.java +469 -0
  14. package/dist/esm/definitions.d.ts +521 -0
  15. package/dist/esm/definitions.js +103 -1
  16. package/dist/esm/definitions.js.map +1 -1
  17. package/dist/esm/index.d.ts +4 -0
  18. package/dist/esm/index.js +6 -1
  19. package/dist/esm/index.js.map +1 -1
  20. package/dist/esm/providers/base-provider.d.ts +43 -0
  21. package/dist/esm/providers/base-provider.js +112 -0
  22. package/dist/esm/providers/base-provider.js.map +1 -0
  23. package/dist/esm/providers/oauth-provider.d.ts +30 -0
  24. package/dist/esm/providers/oauth-provider.js +255 -0
  25. package/dist/esm/providers/oauth-provider.js.map +1 -0
  26. package/dist/esm/providers/provider-factory.d.ts +7 -0
  27. package/dist/esm/providers/provider-factory.js +76 -0
  28. package/dist/esm/providers/provider-factory.js.map +1 -0
  29. package/dist/esm/providers/web/apple-provider.d.ts +33 -0
  30. package/dist/esm/providers/web/apple-provider.js +270 -0
  31. package/dist/esm/providers/web/apple-provider.js.map +1 -0
  32. package/dist/esm/providers/web/google-provider.d.ts +27 -0
  33. package/dist/esm/providers/web/google-provider.js +258 -0
  34. package/dist/esm/providers/web/google-provider.js.map +1 -0
  35. package/dist/esm/utils/auth-error.d.ts +16 -0
  36. package/dist/esm/utils/auth-error.js +53 -0
  37. package/dist/esm/utils/auth-error.js.map +1 -0
  38. package/dist/esm/utils/event-emitter.d.ts +9 -0
  39. package/dist/esm/utils/event-emitter.js +28 -0
  40. package/dist/esm/utils/event-emitter.js.map +1 -0
  41. package/dist/esm/utils/logger.d.ts +19 -0
  42. package/dist/esm/utils/logger.js +48 -0
  43. package/dist/esm/utils/logger.js.map +1 -0
  44. package/dist/esm/utils/storage.d.ts +16 -0
  45. package/dist/esm/utils/storage.js +86 -0
  46. package/dist/esm/utils/storage.js.map +1 -0
  47. package/dist/esm/web.d.ts +43 -0
  48. package/dist/esm/web.js +374 -1
  49. package/dist/esm/web.js.map +1 -1
  50. package/dist/plugin.cjs.js +1650 -0
  51. package/dist/plugin.cjs.js.map +1 -1
  52. package/dist/plugin.js +1652 -3
  53. package/dist/plugin.js.map +1 -1
  54. package/ios/Plugin/AuthLogger.swift +71 -0
  55. package/ios/Plugin/AuthStorage.swift +139 -0
  56. package/ios/Plugin/BaseAuthProvider.swift +33 -0
  57. package/ios/Plugin/CapacitorAuthManager.swift +406 -0
  58. package/ios/Plugin/Models.swift +376 -0
  59. package/ios/Plugin/Plugin.m +27 -0
  60. package/ios/Plugin/Plugin.swift +413 -0
  61. package/package.json +6 -2
  62. package/scripts/configure.js +295 -0
@@ -0,0 +1,79 @@
1
+ ext {
2
+ junitVersion = project.hasProperty('junitVersion') ? rootProject.ext.junitVersion : '4.13.2'
3
+ androidxAppCompatVersion = project.hasProperty('androidxAppCompatVersion') ? rootProject.ext.androidxAppCompatVersion : '1.7.0'
4
+ androidxJunitVersion = project.hasProperty('androidxJunitVersion') ? rootProject.ext.androidxJunitVersion : '1.2.1'
5
+ androidxEspressoCoreVersion = project.hasProperty('androidxEspressoCoreVersion') ? rootProject.ext.androidxEspressoCoreVersion : '3.6.1'
6
+ }
7
+
8
+ buildscript {
9
+ repositories {
10
+ google()
11
+ mavenCentral()
12
+ }
13
+ dependencies {
14
+ classpath 'com.android.tools.build:gradle:8.5.2'
15
+ }
16
+ }
17
+
18
+ apply plugin: 'com.android.library'
19
+
20
+ android {
21
+ namespace "com.aoneahsan.capacitor_auth_manager"
22
+ compileSdk project.hasProperty('compileSdkVersion') ? rootProject.ext.compileSdkVersion : 35
23
+ defaultConfig {
24
+ minSdkVersion project.hasProperty('minSdkVersion') ? rootProject.ext.minSdkVersion : 23
25
+ targetSdkVersion project.hasProperty('targetSdkVersion') ? rootProject.ext.targetSdkVersion : 35
26
+ versionCode 1
27
+ versionName "1.0"
28
+ testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
29
+ }
30
+ buildTypes {
31
+ release {
32
+ minifyEnabled false
33
+ proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro'
34
+ }
35
+ }
36
+ lintOptions {
37
+ abortOnError false
38
+ }
39
+ compileOptions {
40
+ sourceCompatibility JavaVersion.VERSION_17
41
+ targetCompatibility JavaVersion.VERSION_17
42
+ }
43
+ }
44
+
45
+ repositories {
46
+ google()
47
+ mavenCentral()
48
+ }
49
+
50
+ dependencies {
51
+ implementation fileTree(dir: 'libs', include: ['*.jar'])
52
+ implementation project(':capacitor-android')
53
+ implementation "androidx.appcompat:appcompat:$androidxAppCompatVersion"
54
+
55
+ // Google Sign-In
56
+ implementation 'com.google.android.gms:play-services-auth:21.3.0'
57
+
58
+ // Facebook SDK
59
+ implementation 'com.facebook.android:facebook-login:17.0.3'
60
+
61
+ // Microsoft Authentication Library (MSAL)
62
+ implementation 'com.microsoft.identity.client:msal:5.2.0'
63
+
64
+ // Firebase Auth (optional)
65
+ // implementation 'com.google.firebase:firebase-auth:23.2.0'
66
+
67
+ // Biometric
68
+ implementation 'androidx.biometric:biometric:1.1.0'
69
+
70
+ // Coroutines for async operations
71
+ implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.9.0'
72
+
73
+ // Security
74
+ implementation 'androidx.security:security-crypto:1.1.0-alpha06'
75
+
76
+ testImplementation "junit:junit:$junitVersion"
77
+ androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
78
+ androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
79
+ }
@@ -0,0 +1,25 @@
1
+ # Project-wide Gradle settings.
2
+
3
+ # IDE (e.g. Android Studio) users:
4
+ # Gradle settings configured through the IDE *will override*
5
+ # any settings specified in this file.
6
+
7
+ # For more details on how to configure your build environment visit
8
+ # http://www.gradle.org/docs/current/userguide/build_environment.html
9
+
10
+ # Specifies the JVM arguments used for the daemon process.
11
+ # The setting is particularly useful for tweaking memory settings.
12
+ org.gradle.jvmargs=-Xmx1536m
13
+
14
+ # When configured, Gradle will run in incubating parallel mode.
15
+ # This option should only be used with decoupled projects. More details, visit
16
+ # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects
17
+ # org.gradle.parallel=true
18
+
19
+ # AndroidX package structure to make it clearer which packages are bundled with the
20
+ # Android operating system, and which are packaged with your app's APK
21
+ # https://developer.android.com/topic/libraries/support-library/androidx-rn
22
+ android.useAndroidX=true
23
+
24
+ # Automatically convert third-party libraries to use AndroidX
25
+ android.enableJetifier=true
@@ -0,0 +1,38 @@
1
+ # Add project specific ProGuard rules here.
2
+ # You can control the set of applied configuration files using the
3
+ # proguardFiles setting in build.gradle.
4
+ #
5
+ # For more details, see
6
+ # http://developer.android.com/guide/developing/tools/proguard.html
7
+
8
+ # If your project uses WebView with JS, uncomment the following
9
+ # and specify the fully qualified class name to the JavaScript interface
10
+ # class:
11
+ #-keepclassmembers class fqcn.of.javascript.interface.for.webview {
12
+ # public *;
13
+ #}
14
+
15
+ # Uncomment this to preserve the line number information for
16
+ # debugging stack traces.
17
+ #-keepattributes SourceFile,LineNumberTable
18
+
19
+ # If you keep the line number information, uncomment this to
20
+ # hide the original source file name.
21
+ #-renamesourcefileattribute SourceFile
22
+
23
+ # Google Sign-In
24
+ -keep class com.google.android.gms.auth.** { *; }
25
+ -keep class com.google.android.gms.common.** { *; }
26
+
27
+ # Facebook SDK
28
+ -keep class com.facebook.** { *; }
29
+
30
+ # Microsoft Authentication Library
31
+ -keep class com.microsoft.identity.** { *; }
32
+ -keep class com.microsoft.device.** { *; }
33
+
34
+ # Capacitor
35
+ -keep class com.getcapacitor.** { *; }
36
+
37
+ # Plugin classes
38
+ -keep class com.aoneahsan.capacitor_auth_manager.** { *; }
@@ -0,0 +1,2 @@
1
+ include ':capacitor-android'
2
+ project(':capacitor-android').projectDir = new File('../node_modules/@capacitor/android/capacitor')
@@ -0,0 +1,11 @@
1
+ <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <!-- Required for OAuth flows -->
3
+ <uses-permission android:name="android.permission.INTERNET" />
4
+
5
+ <!-- Required for biometric authentication -->
6
+ <uses-permission android:name="android.permission.USE_BIOMETRIC" />
7
+
8
+ <!-- Required for SMS authentication -->
9
+ <uses-permission android:name="android.permission.RECEIVE_SMS" />
10
+ <uses-permission android:name="android.permission.READ_SMS" />
11
+ </manifest>
@@ -0,0 +1,117 @@
1
+ package com.aoneahsan.capacitor_auth_manager;
2
+
3
+ import android.util.Log;
4
+
5
+ public class AuthLogger {
6
+ private static final String PREFIX = "CapacitorAuthManager";
7
+
8
+ public enum LogLevel {
9
+ DEBUG(0, "D"),
10
+ INFO(1, "I"),
11
+ WARN(2, "W"),
12
+ ERROR(3, "E");
13
+
14
+ private final int value;
15
+ private final String tag;
16
+
17
+ LogLevel(int value, String tag) {
18
+ this.value = value;
19
+ this.tag = tag;
20
+ }
21
+
22
+ public int getValue() {
23
+ return value;
24
+ }
25
+
26
+ public String getTag() {
27
+ return tag;
28
+ }
29
+ }
30
+
31
+ private boolean isEnabled = false;
32
+ private LogLevel logLevel = LogLevel.INFO;
33
+ private final String tag;
34
+
35
+ public AuthLogger(String tag) {
36
+ this.tag = tag != null ? tag : PREFIX;
37
+ }
38
+
39
+ public void setEnabled(boolean enabled) {
40
+ this.isEnabled = enabled;
41
+ }
42
+
43
+ public void setLogLevel(String level) {
44
+ if (level == null) return;
45
+
46
+ switch (level.toLowerCase()) {
47
+ case "debug":
48
+ this.logLevel = LogLevel.DEBUG;
49
+ break;
50
+ case "info":
51
+ this.logLevel = LogLevel.INFO;
52
+ break;
53
+ case "warn":
54
+ this.logLevel = LogLevel.WARN;
55
+ break;
56
+ case "error":
57
+ this.logLevel = LogLevel.ERROR;
58
+ break;
59
+ default:
60
+ this.logLevel = LogLevel.INFO;
61
+ }
62
+ }
63
+
64
+ public void debug(String message, Object... args) {
65
+ log(LogLevel.DEBUG, message, args);
66
+ }
67
+
68
+ public void info(String message, Object... args) {
69
+ log(LogLevel.INFO, message, args);
70
+ }
71
+
72
+ public void warn(String message, Object... args) {
73
+ log(LogLevel.WARN, message, args);
74
+ }
75
+
76
+ public void error(String message, Throwable throwable) {
77
+ if (!isEnabled || LogLevel.ERROR.getValue() < logLevel.getValue()) {
78
+ return;
79
+ }
80
+
81
+ if (throwable != null) {
82
+ Log.e(tag, formatMessage(message), throwable);
83
+ } else {
84
+ Log.e(tag, formatMessage(message));
85
+ }
86
+ }
87
+
88
+ private void log(LogLevel level, String message, Object... args) {
89
+ if (!isEnabled || level.getValue() < logLevel.getValue()) {
90
+ return;
91
+ }
92
+
93
+ String formattedMessage = formatMessage(message);
94
+ if (args.length > 0) {
95
+ formattedMessage = String.format(formattedMessage, args);
96
+ }
97
+
98
+ switch (level) {
99
+ case DEBUG:
100
+ Log.d(tag, formattedMessage);
101
+ break;
102
+ case INFO:
103
+ Log.i(tag, formattedMessage);
104
+ break;
105
+ case WARN:
106
+ Log.w(tag, formattedMessage);
107
+ break;
108
+ case ERROR:
109
+ Log.e(tag, formattedMessage);
110
+ break;
111
+ }
112
+ }
113
+
114
+ private String formatMessage(String message) {
115
+ return "[" + PREFIX + "] " + message;
116
+ }
117
+ }
@@ -0,0 +1,124 @@
1
+ package com.aoneahsan.capacitor_auth_manager;
2
+
3
+ import android.content.Context;
4
+ import android.content.SharedPreferences;
5
+ import androidx.security.crypto.EncryptedSharedPreferences;
6
+ import androidx.security.crypto.MasterKey;
7
+
8
+ import com.getcapacitor.JSObject;
9
+
10
+ import org.json.JSONException;
11
+ import org.json.JSONObject;
12
+
13
+ import java.io.IOException;
14
+ import java.security.GeneralSecurityException;
15
+
16
+ public class AuthStorage {
17
+ private static final String PREFS_NAME = "cap_auth_prefs";
18
+ private static final String KEY_PREFIX = "cap_auth_";
19
+
20
+ private final Context context;
21
+ private SharedPreferences sharedPreferences;
22
+ private String persistence = "local";
23
+
24
+ public enum Persistence {
25
+ LOCAL("local"),
26
+ SESSION("session"),
27
+ NONE("none");
28
+
29
+ private final String value;
30
+
31
+ Persistence(String value) {
32
+ this.value = value;
33
+ }
34
+
35
+ public String getValue() {
36
+ return value;
37
+ }
38
+ }
39
+
40
+ public AuthStorage(Context context) {
41
+ this.context = context;
42
+ initializeStorage();
43
+ }
44
+
45
+ private void initializeStorage() {
46
+ try {
47
+ // Use encrypted shared preferences for secure storage
48
+ MasterKey masterKey = new MasterKey.Builder(context)
49
+ .setKeyScheme(MasterKey.KeyScheme.AES256_GCM)
50
+ .build();
51
+
52
+ sharedPreferences = EncryptedSharedPreferences.create(
53
+ context,
54
+ PREFS_NAME,
55
+ masterKey,
56
+ EncryptedSharedPreferences.PrefKeyEncryptionScheme.AES256_SIV,
57
+ EncryptedSharedPreferences.PrefValueEncryptionScheme.AES256_GCM
58
+ );
59
+ } catch (GeneralSecurityException | IOException e) {
60
+ // Fallback to regular shared preferences
61
+ sharedPreferences = context.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
62
+ }
63
+ }
64
+
65
+ public void setPersistence(String persistence) {
66
+ this.persistence = persistence;
67
+ }
68
+
69
+ public String get(String key) {
70
+ if (persistence.equals(Persistence.NONE.getValue())) {
71
+ return null;
72
+ }
73
+ return sharedPreferences.getString(KEY_PREFIX + key, null);
74
+ }
75
+
76
+ public void set(String key, String value) {
77
+ if (persistence.equals(Persistence.NONE.getValue())) {
78
+ return;
79
+ }
80
+ sharedPreferences.edit().putString(KEY_PREFIX + key, value).apply();
81
+ }
82
+
83
+ public void remove(String key) {
84
+ sharedPreferences.edit().remove(KEY_PREFIX + key).apply();
85
+ }
86
+
87
+ public void clear() {
88
+ SharedPreferences.Editor editor = sharedPreferences.edit();
89
+ for (String key : sharedPreferences.getAll().keySet()) {
90
+ if (key.startsWith(KEY_PREFIX)) {
91
+ editor.remove(key);
92
+ }
93
+ }
94
+ editor.apply();
95
+ }
96
+
97
+ public void setLastAuthProvider(String provider) {
98
+ set("last_auth_provider", provider);
99
+ }
100
+
101
+ public String getLastAuthProvider() {
102
+ return get("last_auth_provider");
103
+ }
104
+
105
+ public void removeLastAuthProvider() {
106
+ remove("last_auth_provider");
107
+ }
108
+
109
+ public void setCustomParameters(String provider, JSObject parameters) {
110
+ set(provider + "_custom_params", parameters.toString());
111
+ }
112
+
113
+ public JSObject getCustomParameters(String provider) {
114
+ String jsonString = get(provider + "_custom_params");
115
+ if (jsonString != null) {
116
+ try {
117
+ return JSObject.fromJSONObject(new JSONObject(jsonString));
118
+ } catch (JSONException e) {
119
+ return null;
120
+ }
121
+ }
122
+ return null;
123
+ }
124
+ }
@@ -0,0 +1,16 @@
1
+ package com.aoneahsan.capacitor_auth_manager;
2
+
3
+ import com.getcapacitor.JSObject;
4
+
5
+ public interface BaseAuthProvider {
6
+ void initialize(CapacitorAuthManager.AuthCallback<Void> callback);
7
+ void signIn(JSObject credentials, JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback);
8
+ void signOut(JSObject options, CapacitorAuthManager.AuthCallback<Void> callback);
9
+ void getCurrentUser(CapacitorAuthManager.AuthCallback<JSObject> callback);
10
+ void refreshToken(JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback);
11
+ void isSupported(CapacitorAuthManager.AuthCallback<Boolean> callback);
12
+ void linkAccount(JSObject credentials, JSObject options, CapacitorAuthManager.AuthCallback<JSObject> callback);
13
+ void unlinkAccount(CapacitorAuthManager.AuthCallback<Void> callback);
14
+ void getIdToken(boolean forceRefresh, CapacitorAuthManager.AuthCallback<JSObject> callback);
15
+ void revokeAccess(String token, CapacitorAuthManager.AuthCallback<Void> callback);
16
+ }