@falconeta/capacitor-aws-amplify 0.0.6 → 0.0.8

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 CHANGED
@@ -16,8 +16,10 @@ npx cap sync
16
16
  * [`load(...)`](#load)
17
17
  * [`signIn(...)`](#signin)
18
18
  * [`federatedSignIn(...)`](#federatedsignin)
19
+ * [`fetchAuthSession()`](#fetchauthsession)
19
20
  * [`signOut()`](#signout)
20
21
  * [Interfaces](#interfaces)
22
+ * [Enums](#enums)
21
23
 
22
24
  </docgen-index>
23
25
 
@@ -55,12 +57,23 @@ signIn(options: { email: string; password: string; }) => Promise<CognitoAuthSess
55
57
  ### federatedSignIn(...)
56
58
 
57
59
  ```typescript
58
- federatedSignIn(options: { provider: string; }) => Promise<CognitoAuthSession>
60
+ federatedSignIn(options: { provider: CognitoHostedUIIdentityProvider; }) => Promise<CognitoAuthSession>
59
61
  ```
60
62
 
61
- | Param | Type |
62
- | ------------- | ---------------------------------- |
63
- | **`options`** | <code>{ provider: string; }</code> |
63
+ | Param | Type |
64
+ | ------------- | ---------------------------------------------------------------------------------------------------------- |
65
+ | **`options`** | <code>{ provider: <a href="#cognitohosteduiidentityprovider">CognitoHostedUIIdentityProvider</a>; }</code> |
66
+
67
+ **Returns:** <code>Promise&lt;<a href="#cognitoauthsession">CognitoAuthSession</a>&gt;</code>
68
+
69
+ --------------------
70
+
71
+
72
+ ### fetchAuthSession()
73
+
74
+ ```typescript
75
+ fetchAuthSession() => Promise<CognitoAuthSession>
76
+ ```
64
77
 
65
78
  **Returns:** <code>Promise&lt;<a href="#cognitoauthsession">CognitoAuthSession</a>&gt;</code>
66
79
 
@@ -95,12 +108,35 @@ signOut() => Promise<any>
95
108
 
96
109
  #### CognitoAuthSession
97
110
 
98
- | Prop | Type |
99
- | ------------------ | --------------------------- |
100
- | **`accessToken`** | <code>string</code> |
101
- | **`idToken`** | <code>string</code> |
102
- | **`identityId`** | <code>string</code> |
103
- | **`refreshToken`** | <code>string</code> |
104
- | **`deviceKey`** | <code>string \| null</code> |
111
+ | Prop | Type |
112
+ | ------------------ | ----------------------------------------------------------------------------------------- |
113
+ | **`accessToken`** | <code>string</code> |
114
+ | **`idToken`** | <code>string</code> |
115
+ | **`identityId`** | <code>string</code> |
116
+ | **`refreshToken`** | <code>string</code> |
117
+ | **`deviceKey`** | <code>string \| null</code> |
118
+ | **`status`** | <code><a href="#awsamplifypluginresponsestatus">AwsAmplifyPluginResponseStatus</a></code> |
119
+
120
+
121
+ ### Enums
122
+
123
+
124
+ #### AwsAmplifyPluginResponseStatus
125
+
126
+ | Members | Value |
127
+ | -------- | --------------- |
128
+ | **`Ok`** | <code>0</code> |
129
+ | **`Ko`** | <code>-1</code> |
130
+
131
+
132
+ #### CognitoHostedUIIdentityProvider
133
+
134
+ | Members | Value |
135
+ | -------------- | ------------------------------ |
136
+ | **`Cognito`** | <code>"COGNITO"</code> |
137
+ | **`Google`** | <code>"Google"</code> |
138
+ | **`Facebook`** | <code>"Facebook"</code> |
139
+ | **`Amazon`** | <code>"LoginWithAmazon"</code> |
140
+ | **`Apple`** | <code>"SignInWithApple"</code> |
105
141
 
106
142
  </docgen-api>
@@ -55,4 +55,9 @@ dependencies {
55
55
  testImplementation "junit:junit:$junitVersion"
56
56
  androidTestImplementation "androidx.test.ext:junit:$androidxJunitVersion"
57
57
  androidTestImplementation "androidx.test.espresso:espresso-core:$androidxEspressoCoreVersion"
58
+ // Amplify core dependency
59
+ implementation 'com.amplifyframework:core:1.38.7'
60
+
61
+ // AWS Cognito dependency
62
+ implementation 'com.amplifyframework:aws-auth-cognito:1.38.7'
58
63
  }
@@ -1,2 +1,12 @@
1
1
  <manifest xmlns:android="http://schemas.android.com/apk/res/android">
2
+ <queries>
3
+ <intent>
4
+ <action android:name="android.intent.action.VIEW" />
5
+ <data android:scheme="https" />
6
+ </intent>
7
+ <intent>
8
+ <action android:name=
9
+ "android.support.customtabs.action.CustomTabsService" />
10
+ </intent>
11
+ </queries>
2
12
  </manifest>
@@ -1,11 +1,282 @@
1
1
  package com.capacitor.aws.amplify;
2
2
 
3
+ import android.app.Activity;
4
+ import android.content.Context;
5
+ import android.os.Build;
3
6
  import android.util.Log;
4
7
 
8
+ import androidx.annotation.NonNull;
9
+ import androidx.annotation.Nullable;
10
+ import androidx.annotation.RequiresApi;
11
+
12
+ import com.amazonaws.mobile.client.AWSMobileClient;
13
+ import com.amazonaws.mobile.client.DeviceOperations;
14
+ import com.amazonaws.mobile.client.results.Device;
15
+ import com.amazonaws.mobile.client.results.ListDevicesResult;
16
+ import com.amazonaws.mobile.client.results.Tokens;
17
+ import com.amplifyframework.AmplifyException;
18
+ import com.amplifyframework.auth.AuthCategoryConfiguration;
19
+ import com.amplifyframework.auth.AuthException;
20
+ import com.amplifyframework.auth.AuthProvider;
21
+ import com.amplifyframework.auth.cognito.AWSCognitoAuthPlugin;
22
+ import com.amplifyframework.auth.cognito.AWSCognitoAuthSession;
23
+ import com.amplifyframework.auth.result.AuthSessionResult;
24
+ import com.amplifyframework.auth.result.AuthSignInResult;
25
+ import com.amplifyframework.core.Amplify;
26
+ import com.amplifyframework.core.AmplifyConfiguration;
27
+ import com.amplifyframework.core.category.CategoryConfiguration;
28
+ import com.getcapacitor.JSObject;
29
+
30
+ import org.json.JSONException;
31
+ import org.json.JSONObject;
32
+
33
+ import java.util.HashMap;
34
+ import java.util.List;
35
+ import java.util.Map;
36
+ import java.util.Objects;
37
+ import java.util.function.Consumer;
38
+
5
39
  public class AwsAmplify {
6
40
 
7
- public String echo(String value) {
8
- Log.i("Echo", value);
9
- return value;
41
+ @RequiresApi(api = Build.VERSION_CODES.N)
42
+ public void load(JSObject cognitoConfig, Context context, @NonNull Consumer onSuccess, @NonNull Consumer<Exception> onError) {
43
+
44
+ JSObject oauth = (JSObject) cognitoConfig.getJSObject("oauth");
45
+
46
+ try {
47
+ JSONObject auth = new JSONObject();
48
+ auth.put("plugins", new JSONObject().put(
49
+ "awsCognitoAuthPlugin", new JSONObject().put(
50
+ "IdentityManager", new JSONObject().put(
51
+ "Default", new JSONObject())
52
+ ).put(
53
+ "CredentialsProvider", new JSONObject().put(
54
+ "CognitoIdentity", new JSONObject().put(
55
+ "Default", new JSONObject().put(
56
+ "PoolId", cognitoConfig.get("aws_cognito_identity_pool_id")
57
+ ).put(
58
+ "Region", cognitoConfig.get("aws_cognito_region")
59
+ )
60
+ )
61
+ )
62
+ ).put(
63
+ "CognitoUserPool", new JSONObject().put(
64
+ "Default", new JSONObject().put(
65
+ "PoolId", cognitoConfig.get("aws_user_pools_id")
66
+ ).put(
67
+ "AppClientId", cognitoConfig.get("aws_user_pools_web_client_id")
68
+ ).put(
69
+ "Region", cognitoConfig.get("aws_cognito_region")
70
+ )
71
+ )
72
+ ).put(
73
+ "Auth", new JSONObject().put(
74
+ "Default", new JSONObject().put(
75
+ "authenticationFlowType", "USER_SRP_AUTH"
76
+ ).put(
77
+ "OAuth", new JSONObject().put(
78
+ "WebDomain", oauth.get("domain")
79
+ ).put(
80
+ "AppClientId", cognitoConfig.get("aws_user_pools_web_client_id")
81
+ ).put(
82
+ "SignInRedirectURI", oauth.get("redirectSignIn")
83
+ ).put(
84
+ "SignOutRedirectURI", oauth.get("redirectSignOut")
85
+ ).put(
86
+ "Scopes", oauth.getJSONArray("scope")
87
+ )
88
+ )
89
+ )
90
+ )
91
+ )
92
+ );
93
+
94
+ Amplify.addPlugin(new AWSCognitoAuthPlugin());
95
+ AuthCategoryConfiguration authConfig = new AuthCategoryConfiguration();
96
+ authConfig.populateFromJSON(auth);
97
+ Map<String, CategoryConfiguration> config = new HashMap();
98
+ config.put("auth", authConfig);
99
+ AmplifyConfiguration configuration = new AmplifyConfiguration(config);
100
+ Amplify.configure(configuration, context);
101
+ onSuccess.accept(null);
102
+ } catch (AmplifyException e) {
103
+ onError.accept(e);
104
+ } catch (JSONException e) {
105
+ onError.accept(e);
106
+ throw new RuntimeException(e);
107
+ }
108
+
109
+ }
110
+
111
+
112
+ @RequiresApi(api = Build.VERSION_CODES.N)
113
+ public void federatedSignIn(String providerString, Activity activity, @NonNull Consumer<AuthSignInResult> onSuccess,
114
+ @NonNull Consumer<AuthException> onError) {
115
+ AuthProvider provider = null;
116
+
117
+ if (providerString != null) {
118
+ if (providerString.equals("Google")) {
119
+ provider = AuthProvider.google();
120
+ }
121
+
122
+ if (providerString.equals("facebook")) {
123
+ provider = AuthProvider.facebook();
124
+ }
125
+
126
+ if (providerString.equals("apple")) {
127
+ provider = AuthProvider.apple();
128
+ }
129
+
130
+
131
+ if (provider != null) {
132
+ Amplify.Auth.signInWithSocialWebUI(
133
+ provider,
134
+ activity,
135
+ result -> {
136
+ onSuccess.accept(result);
137
+
138
+ // mAwsService.fetchAuthSession(
139
+ // call::resolve,
140
+ // error -> {
141
+ // Log.e(TAG, "session error: ", error);
142
+ // call.reject(error.toString());
143
+ // });
144
+ },
145
+ error -> {
146
+ onError.accept(error);
147
+ });
148
+ }
149
+ }
150
+ }
151
+
152
+ @RequiresApi(api = Build.VERSION_CODES.N)
153
+ public void fetchAuthSession(@Nullable Consumer<JSObject> onSuccess,
154
+ @Nullable Consumer<Exception> onError) {
155
+ // mFetching = true;
156
+
157
+ fetchSessionInternal(
158
+ authSession -> {
159
+ // mFetching = false;
160
+
161
+ if (authSession != null && onSuccess != null) {
162
+ onSuccess.accept(authSession.toJson());
163
+ }
164
+ },
165
+ error -> {
166
+ // mFetching = false;
167
+
168
+ if (onError != null) {
169
+ String message = error.getMessage();
170
+ String suggestion = error.getRecoverySuggestion();
171
+ Throwable cause = error.getCause();
172
+
173
+ // AwsAuthException authException;
174
+ //
175
+ // if (message != null && cause != null) {
176
+ // authException = new AwsAuthException(message, cause, suggestion);
177
+ // } else
178
+ // authException = new AwsAuthException(
179
+ // Objects.requireNonNullElse(message, "Aws Auth Error"), "Generic");
180
+
181
+ onError.accept(error);
182
+ }
183
+ });
184
+ }
185
+
186
+ @RequiresApi(api = Build.VERSION_CODES.N)
187
+ private void fetchSessionInternal(@Nullable Consumer<AwsAuthSession> onSuccess,
188
+ @Nullable Consumer<AuthException> onError) {
189
+ Amplify.Auth.fetchAuthSession(
190
+ session -> {
191
+ AWSCognitoAuthSession cognitoAuthSession = (AWSCognitoAuthSession) session;
192
+ AuthSessionResult<String> authSessionResult = cognitoAuthSession.getIdentityId();
193
+ AuthSessionResult.Type type = authSessionResult.getType();
194
+ String identityId = authSessionResult.getValue();
195
+
196
+ // Success.
197
+ if (type == AuthSessionResult.Type.SUCCESS && identityId != null) {
198
+ // Log.i(TAG, "IdentityId: " + identityId);
199
+
200
+ try {
201
+ AwsAuthSession authSession = getSessionInternal();
202
+ // setSession(authSession);
203
+
204
+ if (authSession != null && onSuccess != null) {
205
+ onSuccess.accept(authSession);
206
+ }
207
+
208
+ } catch (Exception e) {
209
+ e.printStackTrace();
210
+
211
+ if (onError != null) {
212
+ onError.accept(new AuthException("Error", e.toString()));
213
+ }
214
+ }
215
+ }
216
+
217
+ // Error.
218
+ else {
219
+ AuthException error = cognitoAuthSession.getIdentityId().getError();
220
+ // Log.e(TAG, "IdentityId not present because: " + error);
221
+
222
+ if (onError != null) {
223
+ onError.accept(error);
224
+ }
225
+ }
226
+ },
227
+ error -> {
228
+ // Log.e(TAG, "Session error: ", error);
229
+
230
+ if (onError != null) {
231
+ onError.accept(error);
232
+ }
233
+ });
234
+ }
235
+
236
+ private AwsAuthSession getSessionInternal() {
237
+ try {
238
+ AWSMobileClient mClient = AWSMobileClient.getInstance();
239
+ Tokens tokens = mClient.getTokens();
240
+
241
+ String accessToken = tokens.getAccessToken().getTokenString();
242
+ String idToken = tokens.getIdToken().getTokenString();
243
+ String refreshToken = tokens.getRefreshToken().getTokenString();
244
+
245
+ DeviceOperations deviceOperations = mClient.getDeviceOperations();
246
+ ListDevicesResult devicesList = deviceOperations.list();
247
+ List<Device> devices = devicesList.getDevices();
248
+
249
+ String deviceKey = null;
250
+
251
+ if (!devices.isEmpty()) {
252
+ deviceKey = deviceOperations.get().getDeviceKey();
253
+ }
254
+
255
+ return AwsAuthSession.builder(mClient.getIdentityId())
256
+ .setAccessToken(accessToken)
257
+ .setIdToken(idToken)
258
+ .setRefreshToken(refreshToken)
259
+ .setDeviceKey(deviceKey)
260
+ .build();
261
+ } catch (Exception e) {
262
+ return null;
10
263
  }
264
+ }
265
+
266
+ /**
267
+ * Sign out of the current device.
268
+ *
269
+ * @param onSuccess success callback.
270
+ * @param onError error callback.
271
+ */
272
+ @RequiresApi(api = Build.VERSION_CODES.N)
273
+ public void signOut(@NonNull Consumer<Boolean> onSuccess,
274
+ @NonNull Consumer<AuthException> onError) {
275
+ Amplify.Auth.signOut(
276
+ () -> onSuccess.accept(true),
277
+ error -> {
278
+ onError.accept(error);
279
+ }
280
+ );
281
+ }
11
282
  }
@@ -1,5 +1,9 @@
1
1
  package com.capacitor.aws.amplify;
2
2
 
3
+ import android.os.Build;
4
+
5
+ import androidx.annotation.RequiresApi;
6
+
3
7
  import com.getcapacitor.JSObject;
4
8
  import com.getcapacitor.Plugin;
5
9
  import com.getcapacitor.PluginCall;
@@ -11,12 +15,55 @@ public class AwsAmplifyPlugin extends Plugin {
11
15
 
12
16
  private AwsAmplify implementation = new AwsAmplify();
13
17
 
18
+ @RequiresApi(api = Build.VERSION_CODES.N)
14
19
  @PluginMethod
15
- public void echo(PluginCall call) {
16
- String value = call.getString("value");
20
+ public void load(PluginCall call) {
21
+ var cognitoConfig = call.getObject("cognitoConfig");
17
22
 
18
- JSObject ret = new JSObject();
19
- ret.put("value", implementation.echo(value));
20
- call.resolve(ret);
23
+ implementation.load(
24
+ cognitoConfig,
25
+ bridge.getContext(),
26
+ result -> call.resolve(),
27
+ error -> {
28
+ call.reject(error.toString());
29
+ });
21
30
  }
31
+
32
+ @RequiresApi(api = Build.VERSION_CODES.N)
33
+ @PluginMethod
34
+ public void signOut(PluginCall call) {
35
+
36
+ implementation.signOut(
37
+ result -> call.resolve(),
38
+ error -> {
39
+ call.reject(error.toString());
40
+ });
41
+ }
42
+
43
+ @RequiresApi(api = Build.VERSION_CODES.N)
44
+ @PluginMethod
45
+ public void federatedSignIn(PluginCall call) {
46
+ String provider = call.getString("provider");
47
+
48
+ implementation.federatedSignIn(
49
+ provider,
50
+ this.getActivity(),
51
+ result -> call.resolve(),
52
+ error -> {
53
+ call.reject(error.toString());
54
+ });
55
+ // onSuccess: { data in
56
+ // self.implementation.fetchAuthSession(
57
+ // onSuccess: {session in
58
+ // call.resolve(session)
59
+ // },
60
+ // onError: {error in
61
+ // call.reject(error.localizedDescription)
62
+ // })
63
+
64
+ // onError: { error in
65
+ // print(error)
66
+ // call.reject(error.localizedDescription)
67
+ // })
68
+ }
22
69
  }
@@ -0,0 +1,126 @@
1
+ package com.capacitor.aws.amplify;
2
+
3
+ import androidx.annotation.NonNull;
4
+ import androidx.annotation.Nullable;
5
+
6
+ import com.getcapacitor.JSObject;
7
+ import com.google.gson.Gson;
8
+
9
+ import org.json.JSONException;
10
+
11
+ public class AwsAuthSession {
12
+ @NonNull
13
+ private final String identityId;
14
+
15
+ @NonNull
16
+ private final String accessToken;
17
+
18
+ @NonNull
19
+ private final String idToken;
20
+
21
+ @NonNull
22
+ private final String refreshToken;
23
+
24
+ @Nullable
25
+ private final String deviceKey;
26
+
27
+ /**
28
+ * Constructs a new builder of {@link AwsAuthSession}.
29
+ */
30
+ @NonNull
31
+ public static Builder builder(@NonNull String id) {
32
+ return new Builder(id);
33
+ }
34
+
35
+ AwsAuthSession(@NonNull Builder builder) {
36
+ identityId = builder.mIdentityId;
37
+ accessToken = builder.mAccessToken;
38
+ idToken = builder.mIdToken;
39
+ refreshToken = builder.mRefreshToken;
40
+ deviceKey = builder.mDeviceKey;
41
+ }
42
+
43
+ @NonNull
44
+ public String getIdentityId() {
45
+ return identityId;
46
+ }
47
+
48
+ @NonNull
49
+ public String getAccessToken() {
50
+ return accessToken;
51
+ }
52
+
53
+ @NonNull
54
+ public String getIdToken() {
55
+ return idToken;
56
+ }
57
+
58
+ @NonNull
59
+ public String getRefreshToken() {
60
+ return refreshToken;
61
+ }
62
+
63
+ @Nullable
64
+ public String getDeviceKey() {
65
+ return deviceKey;
66
+ }
67
+
68
+ @Nullable
69
+ public JSObject toJson() {
70
+ try {
71
+ String jsonInString = new Gson().toJson(this);
72
+ return new JSObject(jsonInString);
73
+ } catch (JSONException e) {
74
+ return null;
75
+ }
76
+ }
77
+
78
+ /**
79
+ * Builder for creating an {@link AwsAuthSession}.
80
+ */
81
+ public static final class Builder {
82
+ String mIdentityId;
83
+
84
+ String mAccessToken;
85
+
86
+ String mIdToken;
87
+
88
+ String mRefreshToken;
89
+
90
+ @Nullable
91
+ String mDeviceKey;
92
+
93
+ public Builder(@NonNull String identityId) {
94
+ mIdentityId = identityId;
95
+ }
96
+
97
+ public Builder setAccessToken(String accessToken) {
98
+ mAccessToken = accessToken;
99
+ return this;
100
+ }
101
+
102
+ public Builder setIdToken(String idToken) {
103
+ mIdToken = idToken;
104
+ return this;
105
+ }
106
+
107
+ public Builder setRefreshToken(String refreshToken) {
108
+ mRefreshToken = refreshToken;
109
+ return this;
110
+ }
111
+
112
+ public Builder setDeviceKey(@Nullable String deviceKey) {
113
+ mDeviceKey = deviceKey;
114
+ return this;
115
+ }
116
+
117
+ /**
118
+ * Constructs the {@link AwsAuthSession} defined by this builder.
119
+ */
120
+ @NonNull
121
+ public AwsAuthSession build() {
122
+ return new AwsAuthSession(this);
123
+ }
124
+ }
125
+ }
126
+
package/dist/docs.json CHANGED
@@ -43,22 +43,35 @@
43
43
  },
44
44
  {
45
45
  "name": "federatedSignIn",
46
- "signature": "(options: { provider: string; }) => Promise<CognitoAuthSession>",
46
+ "signature": "(options: { provider: CognitoHostedUIIdentityProvider; }) => Promise<CognitoAuthSession>",
47
47
  "parameters": [
48
48
  {
49
49
  "name": "options",
50
50
  "docs": "",
51
- "type": "{ provider: string; }"
51
+ "type": "{ provider: CognitoHostedUIIdentityProvider; }"
52
52
  }
53
53
  ],
54
54
  "returns": "Promise<CognitoAuthSession>",
55
55
  "tags": [],
56
56
  "docs": "",
57
57
  "complexTypes": [
58
- "CognitoAuthSession"
58
+ "CognitoAuthSession",
59
+ "CognitoHostedUIIdentityProvider"
59
60
  ],
60
61
  "slug": "federatedsignin"
61
62
  },
63
+ {
64
+ "name": "fetchAuthSession",
65
+ "signature": "() => Promise<CognitoAuthSession>",
66
+ "parameters": [],
67
+ "returns": "Promise<CognitoAuthSession>",
68
+ "tags": [],
69
+ "docs": "",
70
+ "complexTypes": [
71
+ "CognitoAuthSession"
72
+ ],
73
+ "slug": "fetchauthsession"
74
+ },
62
75
  {
63
76
  "name": "signOut",
64
77
  "signature": "() => Promise<any>",
@@ -136,14 +149,14 @@
136
149
  "tags": [],
137
150
  "docs": "",
138
151
  "complexTypes": [],
139
- "type": "string"
152
+ "type": "string | undefined"
140
153
  },
141
154
  {
142
155
  "name": "idToken",
143
156
  "tags": [],
144
157
  "docs": "",
145
158
  "complexTypes": [],
146
- "type": "string"
159
+ "type": "string | undefined"
147
160
  },
148
161
  {
149
162
  "name": "identityId",
@@ -157,7 +170,7 @@
157
170
  "tags": [],
158
171
  "docs": "",
159
172
  "complexTypes": [],
160
- "type": "string"
173
+ "type": "string | undefined"
161
174
  },
162
175
  {
163
176
  "name": "deviceKey",
@@ -165,11 +178,75 @@
165
178
  "docs": "",
166
179
  "complexTypes": [],
167
180
  "type": "string | null"
181
+ },
182
+ {
183
+ "name": "status",
184
+ "tags": [],
185
+ "docs": "",
186
+ "complexTypes": [
187
+ "AwsAmplifyPluginResponseStatus"
188
+ ],
189
+ "type": "AwsAmplifyPluginResponseStatus"
190
+ }
191
+ ]
192
+ }
193
+ ],
194
+ "enums": [
195
+ {
196
+ "name": "AwsAmplifyPluginResponseStatus",
197
+ "slug": "awsamplifypluginresponsestatus",
198
+ "members": [
199
+ {
200
+ "name": "Ok",
201
+ "value": "0",
202
+ "tags": [],
203
+ "docs": ""
204
+ },
205
+ {
206
+ "name": "Ko",
207
+ "value": "-1",
208
+ "tags": [],
209
+ "docs": ""
210
+ }
211
+ ]
212
+ },
213
+ {
214
+ "name": "CognitoHostedUIIdentityProvider",
215
+ "slug": "cognitohosteduiidentityprovider",
216
+ "members": [
217
+ {
218
+ "name": "Cognito",
219
+ "value": "\"COGNITO\"",
220
+ "tags": [],
221
+ "docs": ""
222
+ },
223
+ {
224
+ "name": "Google",
225
+ "value": "\"Google\"",
226
+ "tags": [],
227
+ "docs": ""
228
+ },
229
+ {
230
+ "name": "Facebook",
231
+ "value": "\"Facebook\"",
232
+ "tags": [],
233
+ "docs": ""
234
+ },
235
+ {
236
+ "name": "Amazon",
237
+ "value": "\"LoginWithAmazon\"",
238
+ "tags": [],
239
+ "docs": ""
240
+ },
241
+ {
242
+ "name": "Apple",
243
+ "value": "\"SignInWithApple\"",
244
+ "tags": [],
245
+ "docs": ""
168
246
  }
169
247
  ]
170
248
  }
171
249
  ],
172
- "enums": [],
173
250
  "typeAliases": [],
174
251
  "pluginConfigs": []
175
252
  }
@@ -7,16 +7,18 @@ export interface AwsAmplifyPlugin {
7
7
  password: string;
8
8
  }): Promise<CognitoAuthSession>;
9
9
  federatedSignIn(options: {
10
- provider: string;
10
+ provider: CognitoHostedUIIdentityProvider;
11
11
  }): Promise<CognitoAuthSession>;
12
+ fetchAuthSession(): Promise<CognitoAuthSession>;
12
13
  signOut(): Promise<any>;
13
14
  }
14
15
  export interface CognitoAuthSession {
15
- accessToken: string;
16
- idToken: string;
16
+ accessToken?: string;
17
+ idToken?: string;
17
18
  identityId: string;
18
- refreshToken: string;
19
+ refreshToken?: string;
19
20
  deviceKey: string | null;
21
+ status: AwsAmplifyPluginResponseStatus;
20
22
  }
21
23
  export interface AWSCognitoConfig {
22
24
  aws_cognito_region: string;
@@ -32,3 +34,14 @@ export interface AWSCognitoConfig {
32
34
  responseType: 'code';
33
35
  };
34
36
  }
37
+ export declare enum AwsAmplifyPluginResponseStatus {
38
+ Ok = 0,
39
+ Ko = -1
40
+ }
41
+ export declare enum CognitoHostedUIIdentityProvider {
42
+ Cognito = "COGNITO",
43
+ Google = "Google",
44
+ Facebook = "Facebook",
45
+ Amazon = "LoginWithAmazon",
46
+ Apple = "SignInWithApple"
47
+ }
@@ -1,2 +1,14 @@
1
- export {};
1
+ export var AwsAmplifyPluginResponseStatus;
2
+ (function (AwsAmplifyPluginResponseStatus) {
3
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
4
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
5
+ })(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));
6
+ export var CognitoHostedUIIdentityProvider;
7
+ (function (CognitoHostedUIIdentityProvider) {
8
+ CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
9
+ CognitoHostedUIIdentityProvider["Google"] = "Google";
10
+ CognitoHostedUIIdentityProvider["Facebook"] = "Facebook";
11
+ CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
12
+ CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
13
+ })(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));
2
14
  //# sourceMappingURL=definitions.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken: string;\n idToken: string;\n identityId: string;\n refreshToken: string;\n deviceKey: string | null;\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n"]}
1
+ {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,8BAGX;AAHD,WAAY,8BAA8B;IACxC,+EAAM,CAAA;IACN,gFAAO,CAAA;AACT,CAAC,EAHW,8BAA8B,KAA9B,8BAA8B,QAGzC;AAED,MAAM,CAAN,IAAY,+BAMX;AAND,WAAY,+BAA+B;IACzC,sDAAmB,CAAA;IACnB,oDAAiB,CAAA;IACjB,wDAAqB,CAAA;IACrB,6DAA0B,CAAA;IAC1B,4DAAyB,CAAA;AAC3B,CAAC,EANW,+BAA+B,KAA/B,+BAA+B,QAM1C","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: CognitoHostedUIIdentityProvider;\n }): Promise<CognitoAuthSession>;\n fetchAuthSession(): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken?: string;\n idToken?: string;\n identityId: string;\n refreshToken?: string;\n deviceKey: string | null;\n status: AwsAmplifyPluginResponseStatus\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n\nexport enum AwsAmplifyPluginResponseStatus {\n Ok = 0,\n Ko = -1\n}\n\nexport enum CognitoHostedUIIdentityProvider {\n Cognito = \"COGNITO\",\n Google = \"Google\",\n Facebook = \"Facebook\",\n Amazon = \"LoginWithAmazon\",\n Apple = \"SignInWithApple\"\n}\n"]}
package/dist/esm/web.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
- import type { AWSCognitoConfig, AwsAmplifyPlugin, CognitoAuthSession } from './definitions';
2
+ import type { AwsAmplifyPlugin, AWSCognitoConfig, CognitoAuthSession } from './definitions';
3
3
  export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
4
4
  private cognitoConfig?;
5
5
  load(options: {
@@ -12,6 +12,7 @@ export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin
12
12
  federatedSignIn(options: {
13
13
  provider: string;
14
14
  }): Promise<CognitoAuthSession>;
15
+ fetchAuthSession(): Promise<CognitoAuthSession>;
15
16
  signOut(): Promise<any>;
16
17
  private getCognitoAuthSession;
17
18
  }
package/dist/esm/web.js CHANGED
@@ -1,60 +1,54 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import { Amplify, Auth } from 'aws-amplify';
3
+ import { AwsAmplifyPluginResponseStatus } from './definitions';
3
4
  export class AwsAmplifyWeb extends WebPlugin {
4
5
  async load(options) {
5
6
  this.cognitoConfig = options.cognitoConfig;
6
7
  Amplify.configure(Object.assign({}, options.cognitoConfig));
7
8
  }
8
9
  async signIn(options) {
9
- // console.log(LOG_PREFIX, options);
10
10
  if (!this.cognitoConfig) {
11
11
  throw new Error('call load first');
12
12
  }
13
- return new Promise((resolve, reject) => {
14
- Auth.signIn(options.email, options.password).then((user) => {
15
- const cognitoAuthSession = this.getCognitoAuthSession(user,
16
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
17
- this.cognitoConfig.aws_cognito_identity_pool_id);
18
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
19
- });
20
- });
13
+ const user = (await Auth.signIn(options.email, options.password));
14
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
21
15
  }
22
16
  async federatedSignIn(options) {
23
17
  // console.log(LOG_PREFIX, options);
24
18
  if (!this.cognitoConfig) {
25
19
  throw new Error('call load first');
26
20
  }
27
- return new Promise((resolve, reject) => {
28
- Auth.federatedSignIn(options)
29
- .then(_ => {
30
- // console.log(LOG_PREFIX + " credential", cred);
31
- Auth.currentAuthenticatedUser().then(user => {
32
- // console.log(LOG_PREFIX + " user", user);
33
- const cognitoAuthSession = this.getCognitoAuthSession(user,
34
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
35
- this.cognitoConfig.aws_cognito_identity_pool_id);
36
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
37
- });
38
- })
39
- .catch(err => reject(err));
40
- });
21
+ await Auth.federatedSignIn(options);
22
+ return this.fetchAuthSession();
23
+ }
24
+ async fetchAuthSession() {
25
+ if (!this.cognitoConfig) {
26
+ throw new Error('call load first');
27
+ }
28
+ const user = await Auth.currentAuthenticatedUser();
29
+ // console.log(LOG_PREFIX + " user", user);
30
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
31
+ return cognitoAuthSession;
41
32
  }
42
33
  async signOut() {
34
+ if (!this.cognitoConfig) {
35
+ throw new Error('call load first');
36
+ }
43
37
  return Auth.signOut();
44
38
  }
45
39
  getCognitoAuthSession(user, identityId) {
46
40
  const userSession = user.getSignInUserSession();
47
- if (userSession) {
48
- const res = {
49
- accessToken: userSession.getAccessToken().getJwtToken(),
50
- idToken: userSession.getIdToken().getJwtToken(),
51
- identityId: identityId,
52
- refreshToken: userSession.getRefreshToken().getToken(),
53
- deviceKey: userSession.getAccessToken().decodePayload().device_key,
54
- };
55
- return res;
56
- }
57
- return null;
41
+ const res = {
42
+ accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
43
+ idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
44
+ identityId: identityId,
45
+ refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
46
+ deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
47
+ status: userSession
48
+ ? AwsAmplifyPluginResponseStatus.Ok
49
+ : AwsAmplifyPluginResponseStatus.Ko,
50
+ };
51
+ return res;
58
52
  }
59
53
  }
60
54
  //# sourceMappingURL=web.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQ5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAGZ;QACC,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAiB,EAAE,EAAE;gBACtE,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CACnD,IAAI;gBACJ,oEAAoE;gBACpE,IAAI,CAAC,aAAc,CAAC,4BAA4B,CACjD,CAAC;gBACF,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC9D,CAAC,CAAC,CAAC;QACL,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAErB;QACC,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,aAAa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AC;SACZ;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport type {\n AWSCognitoConfig,\n AwsAmplifyPlugin,\n CognitoAuthSession,\n} from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user: CognitoUser) => {\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig!.aws_cognito_identity_pool_id,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options as FederatedSignInOptions)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig!.aws_cognito_identity_pool_id,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n\n async signOut(): Promise<any> {\n return Auth.signOut();\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n if (userSession) {\n const res: CognitoAuthSession = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n\n return null;\n }\n}\n"]}
1
+ {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAO5C,OAAO,EAAE,8BAA8B,EAAE,MAAM,eAAe,CAAC;AAE/D,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAGZ;QACC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QAED,MAAM,IAAI,GAAG,CAAC,MAAM,IAAI,CAAC,MAAM,CAC7B,OAAO,CAAC,KAAK,EACb,OAAO,CAAC,QAAQ,CACjB,CAAgB,CAAC;QAElB,OAAO,IAAI,CAAC,qBAAqB,CAC/B,IAAI,EACJ,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAChD,CAAC;IACJ,CAAC;IAED,KAAK,CAAC,eAAe,CAAC,OAErB;QACC,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,MAAM,IAAI,CA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b,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport type {\n AwsAmplifyPlugin,\n AWSCognitoConfig,\n CognitoAuthSession,\n} from './definitions';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n\n const user = (await Auth.signIn(\n options.email,\n options.password,\n )) as CognitoUser;\n\n return this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n }\n\n async signOut(): Promise<any> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n const res: CognitoAuthSession = {\n accessToken: userSession?.getAccessToken().getJwtToken(),\n idToken: userSession?.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession?.getRefreshToken().getToken(),\n deviceKey: userSession?.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n"]}
@@ -5,6 +5,20 @@ Object.defineProperty(exports, '__esModule', { value: true });
5
5
  var core = require('@capacitor/core');
6
6
  var awsAmplify = require('aws-amplify');
7
7
 
8
+ exports.AwsAmplifyPluginResponseStatus = void 0;
9
+ (function (AwsAmplifyPluginResponseStatus) {
10
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
11
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
12
+ })(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
13
+ exports.CognitoHostedUIIdentityProvider = void 0;
14
+ (function (CognitoHostedUIIdentityProvider) {
15
+ CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
16
+ CognitoHostedUIIdentityProvider["Google"] = "Google";
17
+ CognitoHostedUIIdentityProvider["Facebook"] = "Facebook";
18
+ CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
19
+ CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
20
+ })(exports.CognitoHostedUIIdentityProvider || (exports.CognitoHostedUIIdentityProvider = {}));
21
+
8
22
  const AwsAmplify = core.registerPlugin('AwsAmplify', {
9
23
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AwsAmplifyWeb()),
10
24
  });
@@ -15,55 +29,48 @@ class AwsAmplifyWeb extends core.WebPlugin {
15
29
  awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
16
30
  }
17
31
  async signIn(options) {
18
- // console.log(LOG_PREFIX, options);
19
32
  if (!this.cognitoConfig) {
20
33
  throw new Error('call load first');
21
34
  }
22
- return new Promise((resolve, reject) => {
23
- awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
24
- const cognitoAuthSession = this.getCognitoAuthSession(user,
25
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
26
- this.cognitoConfig.aws_cognito_identity_pool_id);
27
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
28
- });
29
- });
35
+ const user = (await awsAmplify.Auth.signIn(options.email, options.password));
36
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
30
37
  }
31
38
  async federatedSignIn(options) {
32
39
  // console.log(LOG_PREFIX, options);
33
40
  if (!this.cognitoConfig) {
34
41
  throw new Error('call load first');
35
42
  }
36
- return new Promise((resolve, reject) => {
37
- awsAmplify.Auth.federatedSignIn(options)
38
- .then(_ => {
39
- // console.log(LOG_PREFIX + " credential", cred);
40
- awsAmplify.Auth.currentAuthenticatedUser().then(user => {
41
- // console.log(LOG_PREFIX + " user", user);
42
- const cognitoAuthSession = this.getCognitoAuthSession(user,
43
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
44
- this.cognitoConfig.aws_cognito_identity_pool_id);
45
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
46
- });
47
- })
48
- .catch(err => reject(err));
49
- });
43
+ await awsAmplify.Auth.federatedSignIn(options);
44
+ return this.fetchAuthSession();
45
+ }
46
+ async fetchAuthSession() {
47
+ if (!this.cognitoConfig) {
48
+ throw new Error('call load first');
49
+ }
50
+ const user = await awsAmplify.Auth.currentAuthenticatedUser();
51
+ // console.log(LOG_PREFIX + " user", user);
52
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
53
+ return cognitoAuthSession;
50
54
  }
51
55
  async signOut() {
56
+ if (!this.cognitoConfig) {
57
+ throw new Error('call load first');
58
+ }
52
59
  return awsAmplify.Auth.signOut();
53
60
  }
54
61
  getCognitoAuthSession(user, identityId) {
55
62
  const userSession = user.getSignInUserSession();
56
- if (userSession) {
57
- const res = {
58
- accessToken: userSession.getAccessToken().getJwtToken(),
59
- idToken: userSession.getIdToken().getJwtToken(),
60
- identityId: identityId,
61
- refreshToken: userSession.getRefreshToken().getToken(),
62
- deviceKey: userSession.getAccessToken().decodePayload().device_key,
63
- };
64
- return res;
65
- }
66
- return null;
63
+ const res = {
64
+ accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
65
+ idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
66
+ identityId: identityId,
67
+ refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
68
+ deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
69
+ status: userSession
70
+ ? exports.AwsAmplifyPluginResponseStatus.Ok
71
+ : exports.AwsAmplifyPluginResponseStatus.Ko,
72
+ };
73
+ return res;
67
74
  }
68
75
  }
69
76
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AAC/D,CAAC;;ACDM,MAAM,aAAa,SAASC,cAAS,CAAC;AAC7C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AACnD,QAAQC,kBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AACpE,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B;AACA,QAAQ,IAAI,CAAC,IAAI,CAAC,aAAa,EA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AM,CAAC,GAAG,CAAC,CAAC,CAAC;AAC3C,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,OAAO,GAAG;AACpB,QAAQ,OAAOA,eAAI,CAAC,OAAO,EAAE,CAAC;AAC9B,KAAK;AACL,IAAI,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE;AAC5C,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;AACxD,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,MAAM,GAAG,GAAG;AACxB,gBAAgB,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;AACvE,gBAAgB,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;AAC/D,gBAAgB,UAAU,EAAE,UAAU;AACtC,gBAAgB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;AACtE,gBAAgB,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AAClF,aAAa,CAAC;AACd,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDAA+B;AAC1C,CAAC,UAAU,8BAA8B,EAAE;AAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;AACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;AACrF,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,iDAAgC;AAC3C,CAAC,UAAU,+BAA+B,EAAE;AAC5C,IAAI,+BAA+B,CAAC,SAAS,CAAC,GAAG,SAAS,CAAC;AAC3D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,QAAQ,CAAC;AACzD,IAAI,+BAA+B,CAAC,UAAU,CAAC,GAAG,UAAU,CAAC;AAC7D,IAAI,+BAA+B,CAAC,QAAQ,CAAC,GAAG,iBAAiB,CAAC;AAClE,IAAI,+BAA+B,CAAC,OAAO,CAAC,GAAG,iBAAiB,CAAC;AACjE,CAAC,EAAEA,uCAA+B,KAAKA,uCAA+B,GAAG,EAAE,CAAC,CAAC;;ACXxE,MAAC,UAAU,GAAGC,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AAC/D,CAAC;;ACAM,MAAM,aAA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
package/dist/plugin.js CHANGED
@@ -1,6 +1,20 @@
1
1
  var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
2
2
  'use strict';
3
3
 
4
+ exports.AwsAmplifyPluginResponseStatus = void 0;
5
+ (function (AwsAmplifyPluginResponseStatus) {
6
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
7
+ AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
8
+ })(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
9
+ exports.CognitoHostedUIIdentityProvider = void 0;
10
+ (function (CognitoHostedUIIdentityProvider) {
11
+ CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
12
+ CognitoHostedUIIdentityProvider["Google"] = "Google";
13
+ CognitoHostedUIIdentityProvider["Facebook"] = "Facebook";
14
+ CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
15
+ CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
16
+ })(exports.CognitoHostedUIIdentityProvider || (exports.CognitoHostedUIIdentityProvider = {}));
17
+
4
18
  const AwsAmplify = core.registerPlugin('AwsAmplify', {
5
19
  web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AwsAmplifyWeb()),
6
20
  });
@@ -11,55 +25,48 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
11
25
  awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
12
26
  }
13
27
  async signIn(options) {
14
- // console.log(LOG_PREFIX, options);
15
28
  if (!this.cognitoConfig) {
16
29
  throw new Error('call load first');
17
30
  }
18
- return new Promise((resolve, reject) => {
19
- awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
20
- const cognitoAuthSession = this.getCognitoAuthSession(user,
21
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
22
- this.cognitoConfig.aws_cognito_identity_pool_id);
23
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
24
- });
25
- });
31
+ const user = (await awsAmplify.Auth.signIn(options.email, options.password));
32
+ return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
26
33
  }
27
34
  async federatedSignIn(options) {
28
35
  // console.log(LOG_PREFIX, options);
29
36
  if (!this.cognitoConfig) {
30
37
  throw new Error('call load first');
31
38
  }
32
- return new Promise((resolve, reject) => {
33
- awsAmplify.Auth.federatedSignIn(options)
34
- .then(_ => {
35
- // console.log(LOG_PREFIX + " credential", cred);
36
- awsAmplify.Auth.currentAuthenticatedUser().then(user => {
37
- // console.log(LOG_PREFIX + " user", user);
38
- const cognitoAuthSession = this.getCognitoAuthSession(user,
39
- // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
40
- this.cognitoConfig.aws_cognito_identity_pool_id);
41
- cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
42
- });
43
- })
44
- .catch(err => reject(err));
45
- });
39
+ await awsAmplify.Auth.federatedSignIn(options);
40
+ return this.fetchAuthSession();
41
+ }
42
+ async fetchAuthSession() {
43
+ if (!this.cognitoConfig) {
44
+ throw new Error('call load first');
45
+ }
46
+ const user = await awsAmplify.Auth.currentAuthenticatedUser();
47
+ // console.log(LOG_PREFIX + " user", user);
48
+ const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
49
+ return cognitoAuthSession;
46
50
  }
47
51
  async signOut() {
52
+ if (!this.cognitoConfig) {
53
+ throw new Error('call load first');
54
+ }
48
55
  return awsAmplify.Auth.signOut();
49
56
  }
50
57
  getCognitoAuthSession(user, identityId) {
51
58
  const userSession = user.getSignInUserSession();
52
- if (userSession) {
53
- const res = {
54
- accessToken: userSession.getAccessToken().getJwtToken(),
55
- idToken: userSession.getIdToken().getJwtToken(),
56
- identityId: identityId,
57
- refreshToken: userSession.getRefreshToken().getToken(),
58
- deviceKey: userSession.getAccessToken().decodePayload().device_key,
59
- };
60
- return res;
61
- }
62
- return null;
59
+ const res = {
60
+ accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
61
+ idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
62
+ identityId: identityId,
63
+ refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
64
+ deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
65
+ status: userSession
66
+ ? exports.AwsAmplifyPluginResponseStatus.Ok
67
+ : exports.AwsAmplifyPluginResponseStatus.Ko,
68
+ };
69
+ return res;
63
70
  }
64
71
  }
65
72
 
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC;;ICDM,MAAM,aAAa,SAASC,cAAS,CAAC;IAC7C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IACnD,QAAQC,kBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACpE,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B;IACA,QAAQ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;IACjC,YAAY,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,SAAS;IACT,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YAAYC,eAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,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AAU,EAAE;IAC5C,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACxD,QAAQ,IAAI,WAAW,EAAE;IACzB,YAAY,MAAM,GAAG,GAAG;IACxB,gBAAgB,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;IACvE,gBAAgB,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;IAC/D,gBAAgB,UAAU,EAAE,UAAU;IACtC,gBAAgB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;IACtE,gBAAgB,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;IAClF,aAAa,CAAC;IACd,YAAY,OAAO,GAAG,CAAC;IACvB,SAAS;IACT,QAAQ,OAAO,IAAI,CAAC;IACpB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
1
+ {"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export var AwsAmplifyPluginResponseStatus;\n(function (AwsAmplifyPluginResponseStatus) {\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ok\"] = 0] = \"Ok\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"Ko\"] = -1] = \"Ko\";\n})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));\nexport var CognitoHostedUIIdentityProvider;\n(function (CognitoHostedUIIdentityProvider) {\n CognitoHostedUIIdentityProvider[\"Cognito\"] = \"COGNITO\";\n CognitoHostedUIIdentityProvider[\"Google\"] = \"Google\";\n CognitoHostedUIIdentityProvider[\"Facebook\"] = \"Facebook\";\n CognitoHostedUIIdentityProvider[\"Amazon\"] = \"LoginWithAmazon\";\n CognitoHostedUIIdentityProvider[\"Apple\"] = \"SignInWithApple\";\n})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));\n//# sourceMappingURL=definitions.js.map","import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nimport { AwsAmplifyPluginResponseStatus } from './definitions';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n async fetchAuthSession() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n const user = await Auth.currentAuthenticatedUser();\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n const res = {\n accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),\n idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),\n deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,\n status: userSession\n ? AwsAmplifyPluginResponseStatus.Ok\n : AwsAmplifyPluginResponseStatus.Ko,\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AK,CAAC,iBAAiB,CAAC,CAAC;IAC/C,SAAS;IACT,QAAQ,OAAOA,eAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,KAAK;IACL,IAAI,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE;IAC5C,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACxD,QAAQ,MAAM,GAAG,GAAG;IACpB,YAAY,WAAW,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;IAC7H,YAAY,OAAO,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;IACrH,YAAY,UAAU,EAAE,UAAU;IAClC,YAAY,YAAY,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;IAC5H,YAAY,SAAS,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;IACxI,YAAY,MAAM,EAAE,WAAW;IAC/B,kBAAkBL,sCAA8B,CAAC,EAAE;IACnD,kBAAkBA,sCAA8B,CAAC,EAAE;IACnD,SAAS,CAAC;IACV,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
@@ -151,6 +151,9 @@ import AWSMobileClient
151
151
  let deviceKey = accessTokenPayload?.device_key
152
152
 
153
153
  ret["deviceKey"] = deviceKey
154
+ ret["status"] = 0
155
+ } else {
156
+ ret["status"] = -1
154
157
  }
155
158
 
156
159
  // self.sessionSubject.onNext(session)
@@ -8,4 +8,5 @@ CAP_PLUGIN(AwsAmplifyPlugin, "AwsAmplify",
8
8
  CAP_PLUGIN_METHOD(signIn, CAPPluginReturnPromise);
9
9
  CAP_PLUGIN_METHOD(signOut, CAPPluginReturnPromise);
10
10
  CAP_PLUGIN_METHOD(federatedSignIn, CAPPluginReturnPromise);
11
+ CAP_PLUGIN_METHOD(fetchAuthSession, CAPPluginReturnPromise);
11
12
  )
@@ -76,6 +76,16 @@ public class AwsAmplifyPlugin: CAPPlugin {
76
76
  call.reject(error.localizedDescription)
77
77
  })
78
78
  }
79
+ @objc func fetchAuthSession(_ call: CAPPluginCall) {
80
+
81
+ self.implementation.fetchAuthSession(
82
+ onSuccess: {session in
83
+ call.resolve(session)
84
+ },
85
+ onError: {error in
86
+ call.reject(error.localizedDescription)
87
+ })
88
+ }
79
89
 
80
90
  // var permissionCallID: String?
81
91
  // var locationManager: CLLocationManager?
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@falconeta/capacitor-aws-amplify",
3
- "version": "0.0.6",
3
+ "version": "0.0.8",
4
4
  "description": "plugin that handle amplify features",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",