@falconeta/capacitor-aws-amplify 0.0.7 → 0.0.9
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 +32 -9
- package/android/src/main/java/com/capacitor/aws/amplify/AwsAmplify.java +84 -74
- package/android/src/main/java/com/capacitor/aws/amplify/AwsAmplifyPlugin.java +12 -14
- package/dist/docs.json +61 -8
- package/dist/esm/definitions.d.ts +16 -6
- package/dist/esm/definitions.js +7 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +6 -2
- package/dist/esm/web.js +49 -35
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +55 -35
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +55 -35
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AwsAmplify.swift +37 -20
- package/ios/Plugin/AwsAmplifyPlugin.m +1 -0
- package/ios/Plugin/AwsAmplifyPlugin.swift +32 -14
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -16,6 +16,7 @@ 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)
|
|
21
22
|
* [Enums](#enums)
|
|
@@ -68,13 +69,24 @@ federatedSignIn(options: { provider: CognitoHostedUIIdentityProvider; }) => Prom
|
|
|
68
69
|
--------------------
|
|
69
70
|
|
|
70
71
|
|
|
72
|
+
### fetchAuthSession()
|
|
73
|
+
|
|
74
|
+
```typescript
|
|
75
|
+
fetchAuthSession() => Promise<CognitoAuthSession>
|
|
76
|
+
```
|
|
77
|
+
|
|
78
|
+
**Returns:** <code>Promise<<a href="#cognitoauthsession">CognitoAuthSession</a>></code>
|
|
79
|
+
|
|
80
|
+
--------------------
|
|
81
|
+
|
|
82
|
+
|
|
71
83
|
### signOut()
|
|
72
84
|
|
|
73
85
|
```typescript
|
|
74
|
-
signOut() => Promise<
|
|
86
|
+
signOut() => Promise<{ status: AwsAmplifyPluginResponseStatus; }>
|
|
75
87
|
```
|
|
76
88
|
|
|
77
|
-
**Returns:** <code>Promise<
|
|
89
|
+
**Returns:** <code>Promise<{ status: <a href="#awsamplifypluginresponsestatus">AwsAmplifyPluginResponseStatus</a>; }></code>
|
|
78
90
|
|
|
79
91
|
--------------------
|
|
80
92
|
|
|
@@ -96,18 +108,29 @@ signOut() => Promise<any>
|
|
|
96
108
|
|
|
97
109
|
#### CognitoAuthSession
|
|
98
110
|
|
|
99
|
-
| Prop | Type
|
|
100
|
-
| ------------------ |
|
|
101
|
-
| **`accessToken`** | <code>string</code>
|
|
102
|
-
| **`idToken`** | <code>string</code>
|
|
103
|
-
| **`identityId`** | <code>string</code>
|
|
104
|
-
| **`refreshToken`** | <code>string</code>
|
|
105
|
-
| **`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> |
|
|
106
119
|
|
|
107
120
|
|
|
108
121
|
### Enums
|
|
109
122
|
|
|
110
123
|
|
|
124
|
+
#### AwsAmplifyPluginResponseStatus
|
|
125
|
+
|
|
126
|
+
| Members | Value |
|
|
127
|
+
| --------------- | --------------- |
|
|
128
|
+
| **`Ok`** | <code>0</code> |
|
|
129
|
+
| **`Ko`** | <code>-1</code> |
|
|
130
|
+
| **`Cancelled`** | <code>-2</code> |
|
|
131
|
+
| **`SignedOut`** | <code>-3</code> |
|
|
132
|
+
|
|
133
|
+
|
|
111
134
|
#### CognitoHostedUIIdentityProvider
|
|
112
135
|
|
|
113
136
|
| Members | Value |
|
|
@@ -38,18 +38,18 @@ import java.util.function.Consumer;
|
|
|
38
38
|
|
|
39
39
|
public class AwsAmplify {
|
|
40
40
|
|
|
41
|
-
|
|
42
|
-
|
|
41
|
+
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
42
|
+
public void load(JSObject cognitoConfig, Context context, @NonNull Consumer onSuccess, @NonNull Consumer<Exception> onError) {
|
|
43
43
|
|
|
44
|
-
|
|
44
|
+
JSObject oauth = (JSObject) cognitoConfig.getJSObject("oauth");
|
|
45
45
|
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
46
|
+
try {
|
|
47
|
+
JSONObject auth = new JSONObject();
|
|
48
|
+
auth.put("plugins", new JSONObject().put(
|
|
49
49
|
"awsCognitoAuthPlugin", new JSONObject().put(
|
|
50
50
|
"IdentityManager", new JSONObject().put(
|
|
51
51
|
"Default", new JSONObject())
|
|
52
|
-
|
|
52
|
+
).put(
|
|
53
53
|
"CredentialsProvider", new JSONObject().put(
|
|
54
54
|
"CognitoIdentity", new JSONObject().put(
|
|
55
55
|
"Default", new JSONObject().put(
|
|
@@ -88,97 +88,101 @@ public class AwsAmplify {
|
|
|
88
88
|
)
|
|
89
89
|
)
|
|
90
90
|
)
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
}
|
|
108
|
-
|
|
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);
|
|
109
107
|
}
|
|
110
108
|
|
|
109
|
+
}
|
|
110
|
+
|
|
111
111
|
|
|
112
112
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
113
|
-
public void federatedSignIn(String providerString, Activity activity, @NonNull Consumer<
|
|
114
|
-
@NonNull Consumer<
|
|
115
|
-
AuthProvider provider =
|
|
113
|
+
public void federatedSignIn(String providerString, Activity activity, @NonNull Consumer<JSObject> onSuccess,
|
|
114
|
+
@NonNull Consumer<Exception> onError) {
|
|
115
|
+
AuthProvider provider = AuthProvider.google();
|
|
116
116
|
|
|
117
|
-
if (providerString
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
}
|
|
117
|
+
if (providerString.equals("facebook")) {
|
|
118
|
+
provider = AuthProvider.facebook();
|
|
119
|
+
}
|
|
121
120
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
121
|
+
if (providerString.equals("SignInWithApple")) {
|
|
122
|
+
provider = AuthProvider.apple();
|
|
123
|
+
}
|
|
125
124
|
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
125
|
+
AuthProvider finalProvider = provider;
|
|
126
|
+
fetchAuthSession(response -> {
|
|
127
|
+
var status = -1;
|
|
129
128
|
|
|
129
|
+
try {
|
|
130
|
+
status = response.getInt("status");
|
|
131
|
+
} catch (JSONException e) {
|
|
132
|
+
onError.accept(e);
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
130
135
|
|
|
131
|
-
if (
|
|
136
|
+
if (status == 0) {
|
|
137
|
+
onSuccess.accept(response);
|
|
138
|
+
} else {
|
|
132
139
|
Amplify.Auth.signInWithSocialWebUI(
|
|
133
|
-
|
|
140
|
+
finalProvider,
|
|
134
141
|
activity,
|
|
135
142
|
result -> {
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
// call::resolve,
|
|
140
|
-
// error -> {
|
|
141
|
-
// Log.e(TAG, "session error: ", error);
|
|
142
|
-
// call.reject(error.toString());
|
|
143
|
-
// });
|
|
143
|
+
fetchAuthSession(
|
|
144
|
+
onSuccess,
|
|
145
|
+
onError);
|
|
144
146
|
},
|
|
145
147
|
error -> {
|
|
146
148
|
onError.accept(error);
|
|
147
149
|
});
|
|
148
150
|
}
|
|
149
|
-
}
|
|
151
|
+
}, error -> {
|
|
152
|
+
onError.accept(error);
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
|
|
150
156
|
}
|
|
151
157
|
|
|
152
158
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
153
159
|
public void fetchAuthSession(@Nullable Consumer<JSObject> onSuccess,
|
|
154
160
|
@Nullable Consumer<Exception> onError) {
|
|
155
|
-
// mFetching = true;
|
|
156
|
-
|
|
157
161
|
fetchSessionInternal(
|
|
158
162
|
authSession -> {
|
|
159
|
-
// mFetching = false;
|
|
160
163
|
|
|
161
164
|
if (authSession != null && onSuccess != null) {
|
|
162
|
-
|
|
165
|
+
JSObject ret = new JSObject();
|
|
166
|
+
ret.put("status", 0);
|
|
167
|
+
ret.put("accessToken", authSession.getAccessToken());
|
|
168
|
+
ret.put("idToken", authSession.getIdToken());
|
|
169
|
+
ret.put("identityId", authSession.getIdentityId());
|
|
170
|
+
ret.put("refreshToken", authSession.getRefreshToken());
|
|
171
|
+
ret.put("deviceKey", authSession.getDeviceKey());
|
|
172
|
+
onSuccess.accept(ret);
|
|
163
173
|
}
|
|
164
174
|
},
|
|
165
175
|
error -> {
|
|
166
|
-
// mFetching = false;
|
|
167
|
-
|
|
168
176
|
if (onError != null) {
|
|
169
177
|
String message = error.getMessage();
|
|
170
178
|
String suggestion = error.getRecoverySuggestion();
|
|
171
179
|
Throwable cause = error.getCause();
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
// authException = new AwsAuthException(
|
|
179
|
-
// Objects.requireNonNullElse(message, "Aws Auth Error"), "Generic");
|
|
180
|
-
|
|
181
|
-
onError.accept(error);
|
|
180
|
+
JSObject ret = new JSObject();
|
|
181
|
+
ret.put("status", -1);
|
|
182
|
+
if (AuthException.SignedOutException.class.isInstance(error)) {
|
|
183
|
+
ret.put("status", -3);
|
|
184
|
+
}
|
|
185
|
+
onSuccess.accept(ret);
|
|
182
186
|
}
|
|
183
187
|
});
|
|
184
188
|
}
|
|
@@ -242,15 +246,15 @@ public class AwsAmplify {
|
|
|
242
246
|
String idToken = tokens.getIdToken().getTokenString();
|
|
243
247
|
String refreshToken = tokens.getRefreshToken().getTokenString();
|
|
244
248
|
|
|
245
|
-
DeviceOperations deviceOperations = mClient.getDeviceOperations();
|
|
246
|
-
ListDevicesResult devicesList = deviceOperations.list();
|
|
247
|
-
List<Device> devices = devicesList.getDevices();
|
|
249
|
+
// DeviceOperations deviceOperations = mClient.getDeviceOperations();
|
|
250
|
+
// ListDevicesResult devicesList = deviceOperations.list();
|
|
251
|
+
// List<Device> devices = devicesList.getDevices();
|
|
248
252
|
|
|
249
253
|
String deviceKey = null;
|
|
250
254
|
|
|
251
|
-
if (!devices.isEmpty()) {
|
|
252
|
-
deviceKey = deviceOperations.get().getDeviceKey();
|
|
253
|
-
}
|
|
255
|
+
// if (!devices.isEmpty()) {
|
|
256
|
+
// deviceKey = deviceOperations.get().getDeviceKey();
|
|
257
|
+
// }
|
|
254
258
|
|
|
255
259
|
return AwsAuthSession.builder(mClient.getIdentityId())
|
|
256
260
|
.setAccessToken(accessToken)
|
|
@@ -270,12 +274,18 @@ public class AwsAmplify {
|
|
|
270
274
|
* @param onError error callback.
|
|
271
275
|
*/
|
|
272
276
|
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
273
|
-
public void signOut(@NonNull Consumer<
|
|
277
|
+
public void signOut(@NonNull Consumer<JSObject> onSuccess,
|
|
274
278
|
@NonNull Consumer<AuthException> onError) {
|
|
279
|
+
JSObject ret = new JSObject();
|
|
280
|
+
|
|
275
281
|
Amplify.Auth.signOut(
|
|
276
|
-
() ->
|
|
282
|
+
() -> {
|
|
283
|
+
ret.put("status", 0);
|
|
284
|
+
onSuccess.accept(ret);
|
|
285
|
+
},
|
|
277
286
|
error -> {
|
|
278
|
-
|
|
287
|
+
ret.put("status", -1);
|
|
288
|
+
onSuccess.accept(ret);
|
|
279
289
|
}
|
|
280
290
|
);
|
|
281
291
|
}
|
|
@@ -34,7 +34,7 @@ public class AwsAmplifyPlugin extends Plugin {
|
|
|
34
34
|
public void signOut(PluginCall call) {
|
|
35
35
|
|
|
36
36
|
implementation.signOut(
|
|
37
|
-
result -> call.resolve(),
|
|
37
|
+
result -> call.resolve(result),
|
|
38
38
|
error -> {
|
|
39
39
|
call.reject(error.toString());
|
|
40
40
|
});
|
|
@@ -48,22 +48,20 @@ public class AwsAmplifyPlugin extends Plugin {
|
|
|
48
48
|
implementation.federatedSignIn(
|
|
49
49
|
provider,
|
|
50
50
|
this.getActivity(),
|
|
51
|
-
result -> call.resolve(),
|
|
51
|
+
result -> call.resolve(result),
|
|
52
52
|
error -> {
|
|
53
53
|
call.reject(error.toString());
|
|
54
54
|
});
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
// onError: {error in
|
|
61
|
-
// call.reject(error.localizedDescription)
|
|
62
|
-
// })
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
@RequiresApi(api = Build.VERSION_CODES.N)
|
|
58
|
+
@PluginMethod
|
|
59
|
+
public void fetchAuthSession(PluginCall call) {
|
|
63
60
|
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
61
|
+
implementation.fetchAuthSession(
|
|
62
|
+
result -> call.resolve(result),
|
|
63
|
+
error -> {
|
|
64
|
+
call.reject(error.toString());
|
|
65
|
+
});
|
|
68
66
|
}
|
|
69
67
|
}
|
package/dist/docs.json
CHANGED
|
@@ -60,14 +60,28 @@
|
|
|
60
60
|
],
|
|
61
61
|
"slug": "federatedsignin"
|
|
62
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
|
+
},
|
|
63
75
|
{
|
|
64
76
|
"name": "signOut",
|
|
65
|
-
"signature": "() => Promise<
|
|
77
|
+
"signature": "() => Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
|
|
66
78
|
"parameters": [],
|
|
67
|
-
"returns": "Promise<
|
|
79
|
+
"returns": "Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
|
|
68
80
|
"tags": [],
|
|
69
81
|
"docs": "",
|
|
70
|
-
"complexTypes": [
|
|
82
|
+
"complexTypes": [
|
|
83
|
+
"AwsAmplifyPluginResponseStatus"
|
|
84
|
+
],
|
|
71
85
|
"slug": "signout"
|
|
72
86
|
}
|
|
73
87
|
],
|
|
@@ -137,40 +151,79 @@
|
|
|
137
151
|
"tags": [],
|
|
138
152
|
"docs": "",
|
|
139
153
|
"complexTypes": [],
|
|
140
|
-
"type": "string"
|
|
154
|
+
"type": "string | undefined"
|
|
141
155
|
},
|
|
142
156
|
{
|
|
143
157
|
"name": "idToken",
|
|
144
158
|
"tags": [],
|
|
145
159
|
"docs": "",
|
|
146
160
|
"complexTypes": [],
|
|
147
|
-
"type": "string"
|
|
161
|
+
"type": "string | undefined"
|
|
148
162
|
},
|
|
149
163
|
{
|
|
150
164
|
"name": "identityId",
|
|
151
165
|
"tags": [],
|
|
152
166
|
"docs": "",
|
|
153
167
|
"complexTypes": [],
|
|
154
|
-
"type": "string"
|
|
168
|
+
"type": "string | undefined"
|
|
155
169
|
},
|
|
156
170
|
{
|
|
157
171
|
"name": "refreshToken",
|
|
158
172
|
"tags": [],
|
|
159
173
|
"docs": "",
|
|
160
174
|
"complexTypes": [],
|
|
161
|
-
"type": "string"
|
|
175
|
+
"type": "string | undefined"
|
|
162
176
|
},
|
|
163
177
|
{
|
|
164
178
|
"name": "deviceKey",
|
|
165
179
|
"tags": [],
|
|
166
180
|
"docs": "",
|
|
167
181
|
"complexTypes": [],
|
|
168
|
-
"type": "string | null"
|
|
182
|
+
"type": "string | null | undefined"
|
|
183
|
+
},
|
|
184
|
+
{
|
|
185
|
+
"name": "status",
|
|
186
|
+
"tags": [],
|
|
187
|
+
"docs": "",
|
|
188
|
+
"complexTypes": [
|
|
189
|
+
"AwsAmplifyPluginResponseStatus"
|
|
190
|
+
],
|
|
191
|
+
"type": "AwsAmplifyPluginResponseStatus"
|
|
169
192
|
}
|
|
170
193
|
]
|
|
171
194
|
}
|
|
172
195
|
],
|
|
173
196
|
"enums": [
|
|
197
|
+
{
|
|
198
|
+
"name": "AwsAmplifyPluginResponseStatus",
|
|
199
|
+
"slug": "awsamplifypluginresponsestatus",
|
|
200
|
+
"members": [
|
|
201
|
+
{
|
|
202
|
+
"name": "Ok",
|
|
203
|
+
"value": "0",
|
|
204
|
+
"tags": [],
|
|
205
|
+
"docs": ""
|
|
206
|
+
},
|
|
207
|
+
{
|
|
208
|
+
"name": "Ko",
|
|
209
|
+
"value": "-1",
|
|
210
|
+
"tags": [],
|
|
211
|
+
"docs": ""
|
|
212
|
+
},
|
|
213
|
+
{
|
|
214
|
+
"name": "Cancelled",
|
|
215
|
+
"value": "-2",
|
|
216
|
+
"tags": [],
|
|
217
|
+
"docs": ""
|
|
218
|
+
},
|
|
219
|
+
{
|
|
220
|
+
"name": "SignedOut",
|
|
221
|
+
"value": "-3",
|
|
222
|
+
"tags": [],
|
|
223
|
+
"docs": ""
|
|
224
|
+
}
|
|
225
|
+
]
|
|
226
|
+
},
|
|
174
227
|
{
|
|
175
228
|
"name": "CognitoHostedUIIdentityProvider",
|
|
176
229
|
"slug": "cognitohosteduiidentityprovider",
|
|
@@ -9,14 +9,18 @@ export interface AwsAmplifyPlugin {
|
|
|
9
9
|
federatedSignIn(options: {
|
|
10
10
|
provider: CognitoHostedUIIdentityProvider;
|
|
11
11
|
}): Promise<CognitoAuthSession>;
|
|
12
|
-
|
|
12
|
+
fetchAuthSession(): Promise<CognitoAuthSession>;
|
|
13
|
+
signOut(): Promise<{
|
|
14
|
+
status: AwsAmplifyPluginResponseStatus;
|
|
15
|
+
}>;
|
|
13
16
|
}
|
|
14
17
|
export interface CognitoAuthSession {
|
|
15
|
-
accessToken
|
|
16
|
-
idToken
|
|
17
|
-
identityId
|
|
18
|
-
refreshToken
|
|
19
|
-
deviceKey
|
|
18
|
+
accessToken?: string;
|
|
19
|
+
idToken?: string;
|
|
20
|
+
identityId?: string;
|
|
21
|
+
refreshToken?: string;
|
|
22
|
+
deviceKey?: string | null;
|
|
23
|
+
status: AwsAmplifyPluginResponseStatus;
|
|
20
24
|
}
|
|
21
25
|
export interface AWSCognitoConfig {
|
|
22
26
|
aws_cognito_region: string;
|
|
@@ -32,6 +36,12 @@ export interface AWSCognitoConfig {
|
|
|
32
36
|
responseType: 'code';
|
|
33
37
|
};
|
|
34
38
|
}
|
|
39
|
+
export declare enum AwsAmplifyPluginResponseStatus {
|
|
40
|
+
Ok = 0,
|
|
41
|
+
Ko = -1,
|
|
42
|
+
Cancelled = -2,
|
|
43
|
+
SignedOut = -3
|
|
44
|
+
}
|
|
35
45
|
export declare enum CognitoHostedUIIdentityProvider {
|
|
36
46
|
Cognito = "COGNITO",
|
|
37
47
|
Google = "Google",
|
package/dist/esm/definitions.js
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
export var AwsAmplifyPluginResponseStatus;
|
|
2
|
+
(function (AwsAmplifyPluginResponseStatus) {
|
|
3
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ok"] = 0] = "Ok";
|
|
4
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Ko"] = -1] = "Ko";
|
|
5
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
|
|
6
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
|
|
7
|
+
})(AwsAmplifyPluginResponseStatus || (AwsAmplifyPluginResponseStatus = {}));
|
|
1
8
|
export var CognitoHostedUIIdentityProvider;
|
|
2
9
|
(function (CognitoHostedUIIdentityProvider) {
|
|
3
10
|
CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"AAqCA,MAAM,CAAN,IAAY,8BAKX;AALD,WAAY,8BAA8B;IACxC,+EAAM,CAAA;IACN,gFAAO,CAAA;IACP,8FAAc,CAAA;IACd,8FAAc,CAAA;AAChB,CAAC,EALW,8BAA8B,KAA9B,8BAA8B,QAKzC;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<{status: AwsAmplifyPluginResponseStatus}>;\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 Cancelled = -2,\n SignedOut = -3\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,6 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type {
|
|
2
|
+
import type { AwsAmplifyPlugin, AWSCognitoConfig, CognitoAuthSession } from './definitions';
|
|
3
|
+
import { AwsAmplifyPluginResponseStatus } from './definitions';
|
|
3
4
|
export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
|
|
4
5
|
private cognitoConfig?;
|
|
5
6
|
load(options: {
|
|
@@ -12,6 +13,9 @@ export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin
|
|
|
12
13
|
federatedSignIn(options: {
|
|
13
14
|
provider: string;
|
|
14
15
|
}): Promise<CognitoAuthSession>;
|
|
15
|
-
|
|
16
|
+
fetchAuthSession(): Promise<CognitoAuthSession>;
|
|
17
|
+
signOut(): Promise<{
|
|
18
|
+
status: AwsAmplifyPluginResponseStatus;
|
|
19
|
+
}>;
|
|
16
20
|
private getCognitoAuthSession;
|
|
17
21
|
}
|
package/dist/esm/web.js
CHANGED
|
@@ -1,60 +1,74 @@
|
|
|
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
|
-
|
|
14
|
-
Auth.signIn(options.email, options.password)
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
13
|
+
try {
|
|
14
|
+
const user = (await Auth.signIn(options.email, options.password));
|
|
15
|
+
return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
16
|
+
}
|
|
17
|
+
catch (error) {
|
|
18
|
+
const res = {
|
|
19
|
+
status: AwsAmplifyPluginResponseStatus.Ko,
|
|
20
|
+
};
|
|
21
|
+
return res;
|
|
22
|
+
}
|
|
21
23
|
}
|
|
22
24
|
async federatedSignIn(options) {
|
|
23
25
|
// console.log(LOG_PREFIX, options);
|
|
24
26
|
if (!this.cognitoConfig) {
|
|
25
27
|
throw new Error('call load first');
|
|
26
28
|
}
|
|
27
|
-
|
|
28
|
-
|
|
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
|
-
});
|
|
29
|
+
await Auth.federatedSignIn(options);
|
|
30
|
+
return this.fetchAuthSession();
|
|
41
31
|
}
|
|
42
|
-
async
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
32
|
+
async fetchAuthSession() {
|
|
33
|
+
if (!this.cognitoConfig) {
|
|
34
|
+
throw new Error('call load first');
|
|
35
|
+
}
|
|
36
|
+
try {
|
|
37
|
+
const user = await Auth.currentAuthenticatedUser();
|
|
38
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
39
|
+
return cognitoAuthSession;
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
console.log(error);
|
|
48
43
|
const res = {
|
|
49
|
-
|
|
50
|
-
idToken: userSession.getIdToken().getJwtToken(),
|
|
51
|
-
identityId: identityId,
|
|
52
|
-
refreshToken: userSession.getRefreshToken().getToken(),
|
|
53
|
-
deviceKey: userSession.getAccessToken().decodePayload().device_key,
|
|
44
|
+
status: AwsAmplifyPluginResponseStatus.Ko,
|
|
54
45
|
};
|
|
55
46
|
return res;
|
|
56
47
|
}
|
|
57
|
-
|
|
48
|
+
}
|
|
49
|
+
async signOut() {
|
|
50
|
+
if (!this.cognitoConfig) {
|
|
51
|
+
throw new Error('call load first');
|
|
52
|
+
}
|
|
53
|
+
return Auth.signOut()
|
|
54
|
+
.then(() => ({
|
|
55
|
+
status: AwsAmplifyPluginResponseStatus.Ok,
|
|
56
|
+
}))
|
|
57
|
+
.catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));
|
|
58
|
+
}
|
|
59
|
+
getCognitoAuthSession(user, identityId) {
|
|
60
|
+
const userSession = user.getSignInUserSession();
|
|
61
|
+
const res = {
|
|
62
|
+
accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
|
|
63
|
+
idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
|
|
64
|
+
identityId: identityId,
|
|
65
|
+
refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
|
|
66
|
+
deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
|
|
67
|
+
status: userSession
|
|
68
|
+
? AwsAmplifyPluginResponseStatus.Ok
|
|
69
|
+
: AwsAmplifyPluginResponseStatus.Ko,
|
|
70
|
+
};
|
|
71
|
+
return res;
|
|
58
72
|
}
|
|
59
73
|
}
|
|
60
74
|
//# sourceMappingURL=web.js.map
|
package/dist/esm/web.js.map
CHANGED
|
@@ -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;
|
|
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,a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ugin } 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 try {\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 } catch (error) {\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\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 try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession: CognitoAuthSession = this.getCognitoAuthSession(\n user,\n this.cognitoConfig.aws_cognito_identity_pool_id,\n );\n\n return cognitoAuthSession;\n } catch (error) {\n console.log(error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n\n async signOut(): Promise<{ status: AwsAmplifyPluginResponseStatus }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\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"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -5,6 +5,13 @@ 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
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
|
|
13
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
|
|
14
|
+
})(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
|
|
8
15
|
exports.CognitoHostedUIIdentityProvider = void 0;
|
|
9
16
|
(function (CognitoHostedUIIdentityProvider) {
|
|
10
17
|
CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
|
|
@@ -24,55 +31,68 @@ class AwsAmplifyWeb extends core.WebPlugin {
|
|
|
24
31
|
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
25
32
|
}
|
|
26
33
|
async signIn(options) {
|
|
27
|
-
// console.log(LOG_PREFIX, options);
|
|
28
34
|
if (!this.cognitoConfig) {
|
|
29
35
|
throw new Error('call load first');
|
|
30
36
|
}
|
|
31
|
-
|
|
32
|
-
awsAmplify.Auth.signIn(options.email, options.password)
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
37
|
+
try {
|
|
38
|
+
const user = (await awsAmplify.Auth.signIn(options.email, options.password));
|
|
39
|
+
return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
40
|
+
}
|
|
41
|
+
catch (error) {
|
|
42
|
+
const res = {
|
|
43
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
44
|
+
};
|
|
45
|
+
return res;
|
|
46
|
+
}
|
|
39
47
|
}
|
|
40
48
|
async federatedSignIn(options) {
|
|
41
49
|
// console.log(LOG_PREFIX, options);
|
|
42
50
|
if (!this.cognitoConfig) {
|
|
43
51
|
throw new Error('call load first');
|
|
44
52
|
}
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
.then(_ => {
|
|
48
|
-
// console.log(LOG_PREFIX + " credential", cred);
|
|
49
|
-
awsAmplify.Auth.currentAuthenticatedUser().then(user => {
|
|
50
|
-
// console.log(LOG_PREFIX + " user", user);
|
|
51
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
52
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
53
|
-
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
54
|
-
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
55
|
-
});
|
|
56
|
-
})
|
|
57
|
-
.catch(err => reject(err));
|
|
58
|
-
});
|
|
53
|
+
await awsAmplify.Auth.federatedSignIn(options);
|
|
54
|
+
return this.fetchAuthSession();
|
|
59
55
|
}
|
|
60
|
-
async
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
56
|
+
async fetchAuthSession() {
|
|
57
|
+
if (!this.cognitoConfig) {
|
|
58
|
+
throw new Error('call load first');
|
|
59
|
+
}
|
|
60
|
+
try {
|
|
61
|
+
const user = await awsAmplify.Auth.currentAuthenticatedUser();
|
|
62
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
63
|
+
return cognitoAuthSession;
|
|
64
|
+
}
|
|
65
|
+
catch (error) {
|
|
66
|
+
console.log(error);
|
|
66
67
|
const res = {
|
|
67
|
-
|
|
68
|
-
idToken: userSession.getIdToken().getJwtToken(),
|
|
69
|
-
identityId: identityId,
|
|
70
|
-
refreshToken: userSession.getRefreshToken().getToken(),
|
|
71
|
-
deviceKey: userSession.getAccessToken().decodePayload().device_key,
|
|
68
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
72
69
|
};
|
|
73
70
|
return res;
|
|
74
71
|
}
|
|
75
|
-
|
|
72
|
+
}
|
|
73
|
+
async signOut() {
|
|
74
|
+
if (!this.cognitoConfig) {
|
|
75
|
+
throw new Error('call load first');
|
|
76
|
+
}
|
|
77
|
+
return awsAmplify.Auth.signOut()
|
|
78
|
+
.then(() => ({
|
|
79
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ok,
|
|
80
|
+
}))
|
|
81
|
+
.catch(() => ({ status: exports.AwsAmplifyPluginResponseStatus.Ko }));
|
|
82
|
+
}
|
|
83
|
+
getCognitoAuthSession(user, identityId) {
|
|
84
|
+
const userSession = user.getSignInUserSession();
|
|
85
|
+
const res = {
|
|
86
|
+
accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
|
|
87
|
+
idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
|
|
88
|
+
identityId: identityId,
|
|
89
|
+
refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
|
|
90
|
+
deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
|
|
91
|
+
status: userSession
|
|
92
|
+
? exports.AwsAmplifyPluginResponseStatus.Ok
|
|
93
|
+
: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
94
|
+
};
|
|
95
|
+
return res;
|
|
76
96
|
}
|
|
77
97
|
}
|
|
78
98
|
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export 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';\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
|
|
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[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\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 try {\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\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 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 try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n console.log(error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\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,IAAI,8BAA8B,CAAC,8BAA8B,C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Ac,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AACxI,YAAY,MAAM,EAAE,WAAW;AAC/B,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,SAAS,CAAC;AACV,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
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
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["Cancelled"] = -2] = "Cancelled";
|
|
9
|
+
AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus["SignedOut"] = -3] = "SignedOut";
|
|
10
|
+
})(exports.AwsAmplifyPluginResponseStatus || (exports.AwsAmplifyPluginResponseStatus = {}));
|
|
4
11
|
exports.CognitoHostedUIIdentityProvider = void 0;
|
|
5
12
|
(function (CognitoHostedUIIdentityProvider) {
|
|
6
13
|
CognitoHostedUIIdentityProvider["Cognito"] = "COGNITO";
|
|
@@ -20,55 +27,68 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
|
|
|
20
27
|
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
21
28
|
}
|
|
22
29
|
async signIn(options) {
|
|
23
|
-
// console.log(LOG_PREFIX, options);
|
|
24
30
|
if (!this.cognitoConfig) {
|
|
25
31
|
throw new Error('call load first');
|
|
26
32
|
}
|
|
27
|
-
|
|
28
|
-
awsAmplify.Auth.signIn(options.email, options.password)
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
33
|
+
try {
|
|
34
|
+
const user = (await awsAmplify.Auth.signIn(options.email, options.password));
|
|
35
|
+
return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
36
|
+
}
|
|
37
|
+
catch (error) {
|
|
38
|
+
const res = {
|
|
39
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
40
|
+
};
|
|
41
|
+
return res;
|
|
42
|
+
}
|
|
35
43
|
}
|
|
36
44
|
async federatedSignIn(options) {
|
|
37
45
|
// console.log(LOG_PREFIX, options);
|
|
38
46
|
if (!this.cognitoConfig) {
|
|
39
47
|
throw new Error('call load first');
|
|
40
48
|
}
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
.then(_ => {
|
|
44
|
-
// console.log(LOG_PREFIX + " credential", cred);
|
|
45
|
-
awsAmplify.Auth.currentAuthenticatedUser().then(user => {
|
|
46
|
-
// console.log(LOG_PREFIX + " user", user);
|
|
47
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
48
|
-
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
49
|
-
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
50
|
-
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
51
|
-
});
|
|
52
|
-
})
|
|
53
|
-
.catch(err => reject(err));
|
|
54
|
-
});
|
|
49
|
+
await awsAmplify.Auth.federatedSignIn(options);
|
|
50
|
+
return this.fetchAuthSession();
|
|
55
51
|
}
|
|
56
|
-
async
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
52
|
+
async fetchAuthSession() {
|
|
53
|
+
if (!this.cognitoConfig) {
|
|
54
|
+
throw new Error('call load first');
|
|
55
|
+
}
|
|
56
|
+
try {
|
|
57
|
+
const user = await awsAmplify.Auth.currentAuthenticatedUser();
|
|
58
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
59
|
+
return cognitoAuthSession;
|
|
60
|
+
}
|
|
61
|
+
catch (error) {
|
|
62
|
+
console.log(error);
|
|
62
63
|
const res = {
|
|
63
|
-
|
|
64
|
-
idToken: userSession.getIdToken().getJwtToken(),
|
|
65
|
-
identityId: identityId,
|
|
66
|
-
refreshToken: userSession.getRefreshToken().getToken(),
|
|
67
|
-
deviceKey: userSession.getAccessToken().decodePayload().device_key,
|
|
64
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
68
65
|
};
|
|
69
66
|
return res;
|
|
70
67
|
}
|
|
71
|
-
|
|
68
|
+
}
|
|
69
|
+
async signOut() {
|
|
70
|
+
if (!this.cognitoConfig) {
|
|
71
|
+
throw new Error('call load first');
|
|
72
|
+
}
|
|
73
|
+
return awsAmplify.Auth.signOut()
|
|
74
|
+
.then(() => ({
|
|
75
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ok,
|
|
76
|
+
}))
|
|
77
|
+
.catch(() => ({ status: exports.AwsAmplifyPluginResponseStatus.Ko }));
|
|
78
|
+
}
|
|
79
|
+
getCognitoAuthSession(user, identityId) {
|
|
80
|
+
const userSession = user.getSignInUserSession();
|
|
81
|
+
const res = {
|
|
82
|
+
accessToken: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().getJwtToken(),
|
|
83
|
+
idToken: userSession === null || userSession === void 0 ? void 0 : userSession.getIdToken().getJwtToken(),
|
|
84
|
+
identityId: identityId,
|
|
85
|
+
refreshToken: userSession === null || userSession === void 0 ? void 0 : userSession.getRefreshToken().getToken(),
|
|
86
|
+
deviceKey: userSession === null || userSession === void 0 ? void 0 : userSession.getAccessToken().decodePayload().device_key,
|
|
87
|
+
status: userSession
|
|
88
|
+
? exports.AwsAmplifyPluginResponseStatus.Ok
|
|
89
|
+
: exports.AwsAmplifyPluginResponseStatus.Ko,
|
|
90
|
+
};
|
|
91
|
+
return res;
|
|
72
92
|
}
|
|
73
93
|
}
|
|
74
94
|
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/definitions.js","esm/index.js","esm/web.js"],"sourcesContent":["export 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';\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
|
|
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[\"Cancelled\"] = -2] = \"Cancelled\";\n AwsAmplifyPluginResponseStatus[AwsAmplifyPluginResponseStatus[\"SignedOut\"] = -3] = \"SignedOut\";\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 try {\n const user = (await Auth.signIn(options.email, options.password));\n return this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n }\n catch (error) {\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\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 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 try {\n const user = await Auth.currentAuthenticatedUser();\n const cognitoAuthSession = this.getCognitoAuthSession(user, this.cognitoConfig.aws_cognito_identity_pool_id);\n return cognitoAuthSession;\n }\n catch (error) {\n console.log(error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n return res;\n }\n }\n async signOut() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return Auth.signOut()\n .then(() => ({\n status: AwsAmplifyPluginResponseStatus.Ok,\n }))\n .catch(() => ({ status: AwsAmplifyPluginResponseStatus.Ko }));\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,oDAA+B;IAC1C,CAAC,UAAU,8BAA8B,EAAE;IAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,GAAG,IAAI,CAAC;IACpF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IACrF,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;IACnG,CAAC,EAAEA,sCAA8B,KAAKA,sCAA8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B,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -48,7 +48,7 @@ import AWSMobileClient
|
|
|
48
48
|
|
|
49
49
|
public func federatedSignIn(
|
|
50
50
|
provider: String,
|
|
51
|
-
onSuccess: @escaping (
|
|
51
|
+
onSuccess: @escaping (JSObject) -> (),
|
|
52
52
|
onError: @escaping (any Error) -> ()
|
|
53
53
|
) {
|
|
54
54
|
var authProvider: AuthProvider
|
|
@@ -72,13 +72,20 @@ import AWSMobileClient
|
|
|
72
72
|
DispatchQueue.main.async {
|
|
73
73
|
Amplify.Auth.signInWithWebUI(for: authProvider,
|
|
74
74
|
presentationAnchor: UIApplication.shared.windows.first!, options: .preferPrivateSession()) { result in
|
|
75
|
+
var ret: JSObject = [:]
|
|
75
76
|
switch result {
|
|
76
|
-
case .success(
|
|
77
|
-
|
|
78
|
-
onSuccess(
|
|
77
|
+
case .success(_):
|
|
78
|
+
ret["status"] = 0
|
|
79
|
+
onSuccess(ret)
|
|
79
80
|
case .failure(let error):
|
|
80
|
-
|
|
81
|
-
|
|
81
|
+
let cognitoAuthError = error.underlyingError as? AWSCognitoAuthError
|
|
82
|
+
switch cognitoAuthError {
|
|
83
|
+
case .userCancelled:
|
|
84
|
+
ret["status"] = -2
|
|
85
|
+
default:
|
|
86
|
+
ret["status"] = -1
|
|
87
|
+
}
|
|
88
|
+
onSuccess(ret)
|
|
82
89
|
}
|
|
83
90
|
}
|
|
84
91
|
}
|
|
@@ -86,16 +93,20 @@ import AWSMobileClient
|
|
|
86
93
|
}
|
|
87
94
|
|
|
88
95
|
public func signOut(
|
|
89
|
-
onSuccess: @escaping (
|
|
96
|
+
onSuccess: @escaping (JSObject) -> (),
|
|
90
97
|
onError: @escaping (any Error) -> ()
|
|
91
98
|
) {
|
|
92
99
|
Amplify.Auth.signOut() { result in
|
|
100
|
+
var ret: JSObject = [:]
|
|
101
|
+
|
|
93
102
|
switch result {
|
|
94
103
|
case .success:
|
|
95
|
-
|
|
104
|
+
ret["status"] = 0
|
|
105
|
+
onSuccess(ret)
|
|
96
106
|
case .failure(let authError):
|
|
97
107
|
print("\(self.TAG) Sign out failed with error \(authError)")
|
|
98
|
-
|
|
108
|
+
ret["status"] = -1
|
|
109
|
+
onSuccess(ret)
|
|
99
110
|
}
|
|
100
111
|
}
|
|
101
112
|
}
|
|
@@ -133,16 +144,6 @@ import AWSMobileClient
|
|
|
133
144
|
ret["idToken"] = tokens.idToken
|
|
134
145
|
ret["refreshToken"] = tokens.refreshToken
|
|
135
146
|
|
|
136
|
-
// Amplify.Auth.fetchDevices { result in
|
|
137
|
-
// switch result {
|
|
138
|
-
// case .success(let devices):
|
|
139
|
-
// print("\(self.TAG) devices", devices)
|
|
140
|
-
// print("\(self.TAG) device IDs", devices.map(\.id))
|
|
141
|
-
// case .failure(let error):
|
|
142
|
-
// print("\(self.TAG) error", error)
|
|
143
|
-
// }
|
|
144
|
-
// }
|
|
145
|
-
|
|
146
147
|
// Retrieve the device key from the payload of access token
|
|
147
148
|
let accessToken = tokens.accessToken as NSString
|
|
148
149
|
// print("\(self.TAG) accessToken - \(tokens.idToken) ")
|
|
@@ -151,6 +152,9 @@ import AWSMobileClient
|
|
|
151
152
|
let deviceKey = accessTokenPayload?.device_key
|
|
152
153
|
|
|
153
154
|
ret["deviceKey"] = deviceKey
|
|
155
|
+
ret["status"] = 0
|
|
156
|
+
} else {
|
|
157
|
+
ret["status"] = -1
|
|
154
158
|
}
|
|
155
159
|
|
|
156
160
|
// self.sessionSubject.onNext(session)
|
|
@@ -159,8 +163,21 @@ import AWSMobileClient
|
|
|
159
163
|
// print("\(self.TAG) - \(ret)")
|
|
160
164
|
onSuccess(ret)
|
|
161
165
|
} catch {
|
|
166
|
+
var ret: JSObject = [:]
|
|
167
|
+
ret["status"] = -1
|
|
168
|
+
if let authError = error as? AuthError
|
|
169
|
+
{
|
|
170
|
+
let cognitoAuthError = authError
|
|
171
|
+
switch cognitoAuthError {
|
|
172
|
+
case .signedOut:
|
|
173
|
+
ret["status"] = -3
|
|
174
|
+
default:
|
|
175
|
+
ret["status"] = -1
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
onSuccess(ret)
|
|
162
180
|
print("\(self.TAG) Fetch auth session failed with error - \(error)")
|
|
163
|
-
onError(error)
|
|
164
181
|
}
|
|
165
182
|
}
|
|
166
183
|
}
|
|
@@ -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
|
)
|
|
@@ -47,10 +47,8 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
47
47
|
|
|
48
48
|
@objc func signOut(_ call: CAPPluginCall) {
|
|
49
49
|
self.implementation.signOut(
|
|
50
|
-
onSuccess: {
|
|
51
|
-
call.resolve(
|
|
52
|
-
"logout": success
|
|
53
|
-
])
|
|
50
|
+
onSuccess: { response in
|
|
51
|
+
call.resolve(response)
|
|
54
52
|
}, onError: { error in
|
|
55
53
|
call.reject(error.localizedDescription)
|
|
56
54
|
})
|
|
@@ -59,22 +57,42 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
59
57
|
@objc func federatedSignIn(_ call: CAPPluginCall) {
|
|
60
58
|
let provider = call.getString("provider") ?? ""
|
|
61
59
|
|
|
62
|
-
self.implementation.
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
60
|
+
self.implementation.fetchAuthSession(
|
|
61
|
+
onSuccess: {session in
|
|
62
|
+
if(session["status"] as! Int == 0) {
|
|
63
|
+
call.resolve(session)
|
|
64
|
+
} else {
|
|
65
|
+
self.implementation.federatedSignIn(
|
|
66
|
+
provider: provider,
|
|
67
|
+
onSuccess: { result in
|
|
68
|
+
if(result["status"] as! Int == 0) {
|
|
69
|
+
self.fetchAuthSession(call)
|
|
70
|
+
} else {
|
|
71
|
+
call.resolve(result)
|
|
72
|
+
}
|
|
73
|
+
},
|
|
74
|
+
onError: { error in
|
|
75
|
+
print(error)
|
|
76
|
+
call.reject(error.localizedDescription)
|
|
77
|
+
})
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
},
|
|
81
|
+
onError: {error in
|
|
82
|
+
call.reject(error.localizedDescription)
|
|
83
|
+
})
|
|
84
|
+
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
@objc func fetchAuthSession(_ call: CAPPluginCall) {
|
|
88
|
+
|
|
89
|
+
self.implementation.fetchAuthSession(
|
|
67
90
|
onSuccess: {session in
|
|
68
91
|
call.resolve(session)
|
|
69
92
|
},
|
|
70
93
|
onError: {error in
|
|
71
94
|
call.reject(error.localizedDescription)
|
|
72
95
|
})
|
|
73
|
-
},
|
|
74
|
-
onError: { error in
|
|
75
|
-
print(error)
|
|
76
|
-
call.reject(error.localizedDescription)
|
|
77
|
-
})
|
|
78
96
|
}
|
|
79
97
|
|
|
80
98
|
// var permissionCallID: String?
|