@falconeta/capacitor-aws-amplify 0.0.16 → 0.0.18
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 +35 -0
- package/dist/docs.json +103 -0
- package/dist/esm/definitions.d.ts +23 -0
- package/dist/esm/definitions.js +29 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +9 -1
- package/dist/esm/web.js +27 -0
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +56 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +56 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AwsAmplify.swift +89 -57
- package/ios/Plugin/AwsAmplifyPlugin.swift +75 -23
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -18,6 +18,7 @@ npx cap sync
|
|
|
18
18
|
* [`federatedSignIn(...)`](#federatedsignin)
|
|
19
19
|
* [`fetchAuthSession()`](#fetchauthsession)
|
|
20
20
|
* [`getUserAttributes()`](#getuserattributes)
|
|
21
|
+
* [`updateUserAttributes(...)`](#updateuserattributes)
|
|
21
22
|
* [`signOut()`](#signout)
|
|
22
23
|
* [Interfaces](#interfaces)
|
|
23
24
|
* [Type Aliases](#type-aliases)
|
|
@@ -93,6 +94,21 @@ getUserAttributes() => Promise<{ status: AwsAmplifyPluginResponseStatus; userAtt
|
|
|
93
94
|
--------------------
|
|
94
95
|
|
|
95
96
|
|
|
97
|
+
### updateUserAttributes(...)
|
|
98
|
+
|
|
99
|
+
```typescript
|
|
100
|
+
updateUserAttributes(options: { attributes: { name: AuthUserAttributeKey | string; value: string; }[]; }) => Promise<{ status: AwsAmplifyPluginResponseStatus; }>
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
| Param | Type |
|
|
104
|
+
| ------------- | ---------------------------------------------------------------- |
|
|
105
|
+
| **`options`** | <code>{ attributes: { name: string; value: string; }[]; }</code> |
|
|
106
|
+
|
|
107
|
+
**Returns:** <code>Promise<{ status: <a href="#awsamplifypluginresponsestatus">AwsAmplifyPluginResponseStatus</a>; }></code>
|
|
108
|
+
|
|
109
|
+
--------------------
|
|
110
|
+
|
|
111
|
+
|
|
96
112
|
### signOut()
|
|
97
113
|
|
|
98
114
|
```typescript
|
|
@@ -164,4 +180,23 @@ Construct a type with a set of properties K of type T
|
|
|
164
180
|
| **`Amazon`** | <code>'LoginWithAmazon'</code> |
|
|
165
181
|
| **`Apple`** | <code>'SignInWithApple'</code> |
|
|
166
182
|
|
|
183
|
+
|
|
184
|
+
#### AuthUserAttributeKey
|
|
185
|
+
|
|
186
|
+
| Members | Value |
|
|
187
|
+
| ----------------------- | -------------------------------- |
|
|
188
|
+
| **`address`** | <code>'address'</code> |
|
|
189
|
+
| **`birthDate`** | <code>'birthDate'</code> |
|
|
190
|
+
| **`email`** | <code>'email'</code> |
|
|
191
|
+
| **`familyName`** | <code>'familyName'</code> |
|
|
192
|
+
| **`gender`** | <code>'gender'</code> |
|
|
193
|
+
| **`givenName`** | <code>'givenName'</code> |
|
|
194
|
+
| **`locale`** | <code>'locale'</code> |
|
|
195
|
+
| **`middleName`** | <code>'middleName'</code> |
|
|
196
|
+
| **`name`** | <code>'name'</code> |
|
|
197
|
+
| **`nickname`** | <code>'nickname'</code> |
|
|
198
|
+
| **`phoneNumber`** | <code>'phoneNumber'</code> |
|
|
199
|
+
| **`picture`** | <code>'picture'</code> |
|
|
200
|
+
| **`preferredUsername`** | <code>'preferredUsername'</code> |
|
|
201
|
+
|
|
167
202
|
</docgen-api>
|
package/dist/docs.json
CHANGED
|
@@ -85,6 +85,25 @@
|
|
|
85
85
|
],
|
|
86
86
|
"slug": "getuserattributes"
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
"name": "updateUserAttributes",
|
|
90
|
+
"signature": "(options: { attributes: { name: AuthUserAttributeKey | string; value: string; }[]; }) => Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
|
|
91
|
+
"parameters": [
|
|
92
|
+
{
|
|
93
|
+
"name": "options",
|
|
94
|
+
"docs": "",
|
|
95
|
+
"type": "{ attributes: { name: string; value: string; }[]; }"
|
|
96
|
+
}
|
|
97
|
+
],
|
|
98
|
+
"returns": "Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
|
|
99
|
+
"tags": [],
|
|
100
|
+
"docs": "",
|
|
101
|
+
"complexTypes": [
|
|
102
|
+
"AwsAmplifyPluginResponseStatus",
|
|
103
|
+
"AuthUserAttributeKey"
|
|
104
|
+
],
|
|
105
|
+
"slug": "updateuserattributes"
|
|
106
|
+
},
|
|
88
107
|
{
|
|
89
108
|
"name": "signOut",
|
|
90
109
|
"signature": "() => Promise<{ status: AwsAmplifyPluginResponseStatus; }>",
|
|
@@ -272,6 +291,90 @@
|
|
|
272
291
|
"docs": ""
|
|
273
292
|
}
|
|
274
293
|
]
|
|
294
|
+
},
|
|
295
|
+
{
|
|
296
|
+
"name": "AuthUserAttributeKey",
|
|
297
|
+
"slug": "authuserattributekey",
|
|
298
|
+
"members": [
|
|
299
|
+
{
|
|
300
|
+
"name": "address",
|
|
301
|
+
"value": "'address'",
|
|
302
|
+
"tags": [],
|
|
303
|
+
"docs": ""
|
|
304
|
+
},
|
|
305
|
+
{
|
|
306
|
+
"name": "birthDate",
|
|
307
|
+
"value": "'birthDate'",
|
|
308
|
+
"tags": [],
|
|
309
|
+
"docs": ""
|
|
310
|
+
},
|
|
311
|
+
{
|
|
312
|
+
"name": "email",
|
|
313
|
+
"value": "'email'",
|
|
314
|
+
"tags": [],
|
|
315
|
+
"docs": ""
|
|
316
|
+
},
|
|
317
|
+
{
|
|
318
|
+
"name": "familyName",
|
|
319
|
+
"value": "'familyName'",
|
|
320
|
+
"tags": [],
|
|
321
|
+
"docs": ""
|
|
322
|
+
},
|
|
323
|
+
{
|
|
324
|
+
"name": "gender",
|
|
325
|
+
"value": "'gender'",
|
|
326
|
+
"tags": [],
|
|
327
|
+
"docs": ""
|
|
328
|
+
},
|
|
329
|
+
{
|
|
330
|
+
"name": "givenName",
|
|
331
|
+
"value": "'givenName'",
|
|
332
|
+
"tags": [],
|
|
333
|
+
"docs": ""
|
|
334
|
+
},
|
|
335
|
+
{
|
|
336
|
+
"name": "locale",
|
|
337
|
+
"value": "'locale'",
|
|
338
|
+
"tags": [],
|
|
339
|
+
"docs": ""
|
|
340
|
+
},
|
|
341
|
+
{
|
|
342
|
+
"name": "middleName",
|
|
343
|
+
"value": "'middleName'",
|
|
344
|
+
"tags": [],
|
|
345
|
+
"docs": ""
|
|
346
|
+
},
|
|
347
|
+
{
|
|
348
|
+
"name": "name",
|
|
349
|
+
"value": "'name'",
|
|
350
|
+
"tags": [],
|
|
351
|
+
"docs": ""
|
|
352
|
+
},
|
|
353
|
+
{
|
|
354
|
+
"name": "nickname",
|
|
355
|
+
"value": "'nickname'",
|
|
356
|
+
"tags": [],
|
|
357
|
+
"docs": ""
|
|
358
|
+
},
|
|
359
|
+
{
|
|
360
|
+
"name": "phoneNumber",
|
|
361
|
+
"value": "'phoneNumber'",
|
|
362
|
+
"tags": [],
|
|
363
|
+
"docs": ""
|
|
364
|
+
},
|
|
365
|
+
{
|
|
366
|
+
"name": "picture",
|
|
367
|
+
"value": "'picture'",
|
|
368
|
+
"tags": [],
|
|
369
|
+
"docs": ""
|
|
370
|
+
},
|
|
371
|
+
{
|
|
372
|
+
"name": "preferredUsername",
|
|
373
|
+
"value": "'preferredUsername'",
|
|
374
|
+
"tags": [],
|
|
375
|
+
"docs": ""
|
|
376
|
+
}
|
|
377
|
+
]
|
|
275
378
|
}
|
|
276
379
|
],
|
|
277
380
|
"typeAliases": [
|
|
@@ -14,6 +14,14 @@ export interface AwsAmplifyPlugin {
|
|
|
14
14
|
status: AwsAmplifyPluginResponseStatus;
|
|
15
15
|
userAttributes: Record<string, string>;
|
|
16
16
|
}>;
|
|
17
|
+
updateUserAttributes(options: {
|
|
18
|
+
attributes: {
|
|
19
|
+
name: AuthUserAttributeKey | string;
|
|
20
|
+
value: string;
|
|
21
|
+
}[];
|
|
22
|
+
}): Promise<{
|
|
23
|
+
status: AwsAmplifyPluginResponseStatus;
|
|
24
|
+
}>;
|
|
17
25
|
signOut(): Promise<{
|
|
18
26
|
status: AwsAmplifyPluginResponseStatus;
|
|
19
27
|
}>;
|
|
@@ -53,3 +61,18 @@ export declare enum CognitoHostedUIIdentityProvider {
|
|
|
53
61
|
Amazon = "LoginWithAmazon",
|
|
54
62
|
Apple = "SignInWithApple"
|
|
55
63
|
}
|
|
64
|
+
export declare enum AuthUserAttributeKey {
|
|
65
|
+
address = "address",
|
|
66
|
+
birthDate = "birthDate",
|
|
67
|
+
email = "email",
|
|
68
|
+
familyName = "familyName",
|
|
69
|
+
gender = "gender",
|
|
70
|
+
givenName = "givenName",
|
|
71
|
+
locale = "locale",
|
|
72
|
+
middleName = "middleName",
|
|
73
|
+
name = "name",
|
|
74
|
+
nickname = "nickname",
|
|
75
|
+
phoneNumber = "phoneNumber",
|
|
76
|
+
picture = "picture",
|
|
77
|
+
preferredUsername = "preferredUsername"
|
|
78
|
+
}
|
package/dist/esm/definitions.js
CHANGED
|
@@ -13,4 +13,33 @@ export var CognitoHostedUIIdentityProvider;
|
|
|
13
13
|
CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
|
|
14
14
|
CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
|
|
15
15
|
})(CognitoHostedUIIdentityProvider || (CognitoHostedUIIdentityProvider = {}));
|
|
16
|
+
export var AuthUserAttributeKey;
|
|
17
|
+
(function (AuthUserAttributeKey) {
|
|
18
|
+
/// Attribute key for user's address
|
|
19
|
+
AuthUserAttributeKey["address"] = "address";
|
|
20
|
+
/// Attribute key for user's birthdate
|
|
21
|
+
AuthUserAttributeKey["birthDate"] = "birthDate";
|
|
22
|
+
/// Attribute key for user's email
|
|
23
|
+
AuthUserAttributeKey["email"] = "email";
|
|
24
|
+
/// Attribute key for user's family name
|
|
25
|
+
AuthUserAttributeKey["familyName"] = "familyName";
|
|
26
|
+
/// Attribute key for user's gender
|
|
27
|
+
AuthUserAttributeKey["gender"] = "gender";
|
|
28
|
+
/// Attribute key for user's given name
|
|
29
|
+
AuthUserAttributeKey["givenName"] = "givenName";
|
|
30
|
+
/// Attribute key for user's locale
|
|
31
|
+
AuthUserAttributeKey["locale"] = "locale";
|
|
32
|
+
/// Attribute key for user's middle name
|
|
33
|
+
AuthUserAttributeKey["middleName"] = "middleName";
|
|
34
|
+
/// Attribute key for user's name
|
|
35
|
+
AuthUserAttributeKey["name"] = "name";
|
|
36
|
+
/// Attribute key for user's nickname
|
|
37
|
+
AuthUserAttributeKey["nickname"] = "nickname";
|
|
38
|
+
/// Attribute key for user's phone number
|
|
39
|
+
AuthUserAttributeKey["phoneNumber"] = "phoneNumber";
|
|
40
|
+
/// Attribute key for user's picture
|
|
41
|
+
AuthUserAttributeKey["picture"] = "picture";
|
|
42
|
+
/// Attribute key for user's preferred user name
|
|
43
|
+
AuthUserAttributeKey["preferredUsername"] = "preferredUsername";
|
|
44
|
+
})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));
|
|
16
45
|
//# sourceMappingURL=definitions.js.map
|
|
@@ -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":"AA8CA,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;AAED,MAAM,CAAN,IAAY,oBAuCX;AAvCD,WAAY,oBAAoB;IAC9B,oCAAoC;IACpC,2CAAmB,CAAA;IAEnB,sCAAsC;IACtC,+CAAuB,CAAA;IAEvB,kCAAkC;IAClC,uCAAe,CAAA;IAEf,wCAAwC;IACxC,iDAAyB,CAAA;IAEzB,mCAAmC;IACnC,yCAAiB,CAAA;IAEjB,uCAAuC;IACvC,+CAAuB,CAAA;IAEvB,mCAAmC;IACnC,yCAAiB,CAAA;IAEjB,wCAAwC;IACxC,iDAAyB,CAAA;IAEzB,iCAAiC;IACjC,qCAAa,CAAA;IAEb,qCAAqC;IACrC,6CAAqB,CAAA;IAErB,yCAAyC;IACzC,mDAA2B,CAAA;IAE3B,oCAAoC;IACpC,2CAAmB,CAAA;IAEnB,gDAAgD;IAChD,+DAAuC,CAAA;AACzC,CAAC,EAvCW,oBAAoB,KAApB,oBAAoB,QAuC/B","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 getUserAttributes(): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }>;\n updateUserAttributes(options: {\n attributes: { name: AuthUserAttributeKey | string; value: string }[];\n }): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n }>;\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\nexport enum AuthUserAttributeKey {\n /// Attribute key for user's address\n address = 'address',\n\n /// Attribute key for user's birthdate\n birthDate = 'birthDate',\n\n /// Attribute key for user's email\n email = 'email',\n\n /// Attribute key for user's family name\n familyName = 'familyName',\n\n /// Attribute key for user's gender\n gender = 'gender',\n\n /// Attribute key for user's given name\n givenName = 'givenName',\n\n /// Attribute key for user's locale\n locale = 'locale',\n\n /// Attribute key for user's middle name\n middleName = 'middleName',\n\n /// Attribute key for user's name\n name = 'name',\n\n /// Attribute key for user's nickname\n nickname = 'nickname',\n\n /// Attribute key for user's phone number\n phoneNumber = 'phoneNumber',\n\n /// Attribute key for user's picture\n picture = 'picture',\n\n /// Attribute key for user's preferred user name\n preferredUsername = 'preferredUsername',\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { AwsAmplifyPlugin, AWSCognitoConfig, CognitoAuthSession } from './definitions';
|
|
2
|
+
import type { AuthUserAttributeKey, AwsAmplifyPlugin, AWSCognitoConfig, CognitoAuthSession } from './definitions';
|
|
3
3
|
import { AwsAmplifyPluginResponseStatus } from './definitions';
|
|
4
4
|
export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
|
|
5
5
|
private cognitoConfig?;
|
|
@@ -18,6 +18,14 @@ export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin
|
|
|
18
18
|
status: AwsAmplifyPluginResponseStatus;
|
|
19
19
|
userAttributes: Record<string, string>;
|
|
20
20
|
}>;
|
|
21
|
+
updateUserAttributes(options: {
|
|
22
|
+
attributes: {
|
|
23
|
+
name: AuthUserAttributeKey | string;
|
|
24
|
+
value: string;
|
|
25
|
+
}[];
|
|
26
|
+
}): Promise<{
|
|
27
|
+
status: AwsAmplifyPluginResponseStatus;
|
|
28
|
+
}>;
|
|
21
29
|
signOut(): Promise<{
|
|
22
30
|
status: AwsAmplifyPluginResponseStatus;
|
|
23
31
|
}>;
|
package/dist/esm/web.js
CHANGED
|
@@ -75,6 +75,33 @@ export class AwsAmplifyWeb extends WebPlugin {
|
|
|
75
75
|
return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });
|
|
76
76
|
}
|
|
77
77
|
}
|
|
78
|
+
async updateUserAttributes(options) {
|
|
79
|
+
if (!this.cognitoConfig) {
|
|
80
|
+
throw new Error('call load first');
|
|
81
|
+
}
|
|
82
|
+
try {
|
|
83
|
+
const user = await Auth.currentAuthenticatedUser();
|
|
84
|
+
return new Promise((resolve, reject) => {
|
|
85
|
+
user.updateAttributes(options.attributes.map(({ name, value }) => ({
|
|
86
|
+
Name: name,
|
|
87
|
+
Value: value,
|
|
88
|
+
})), (error, _, metadata) => {
|
|
89
|
+
console.log('FROM updateUserAttributes', metadata);
|
|
90
|
+
if (error) {
|
|
91
|
+
reject(error);
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
resolve({
|
|
95
|
+
status: AwsAmplifyPluginResponseStatus.Ok,
|
|
96
|
+
});
|
|
97
|
+
return;
|
|
98
|
+
});
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
catch (error) {
|
|
102
|
+
return Object.assign({}, this.handleError(error, 'updateUserAttributes'));
|
|
103
|
+
}
|
|
104
|
+
}
|
|
78
105
|
async signOut() {
|
|
79
106
|
if (!this.cognitoConfig) {
|
|
80
107
|
throw new Error('call load first');
|
package/dist/esm/web.js.map
CHANGED
|
@@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QAAQ,EAAE;YACvD,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,aAAa,GAAG,UAAU;YACnE,MAAM,EAAE,WAAW;gBACjB,CAAC,CAAC,8BAA8B,CAAC,EAAE;gBACnC,CAAC,CAAC,8BAA8B,CAAC,EAAE;SACtC,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,WAAW,CAAC,KAAU,EAAE,IAAY;QAC1C,OAAO,CAAC,KAAK,CAAC,wCAAwC,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,GAAG,GAAuB;YAC9B,MAAM,EAAE,8BAA8B,CAAC,EAAE;SAC1C,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,GAAG,CAAC;SACZ;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACvC,GAAG,CAAC,MAAM,GAAG,8BAA8B,CAAC,SAAS,CAAC;SACvD;QACD,OAAO,GAAG,CAAC;IACb,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 try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 } catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n } catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = 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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n\n async getUserAttributes(): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes:\n attributes?.reduce(\n (acc, data) => ({ ...acc, [data.Name]: data.Value }),\n {},\n ) || {},\n });\n return;\n });\n });\n } catch (error) {\n return {\n ...this.handleError(error, 'getUserAttributes'),\n userAttributes: {},\n };\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(error => this.handleError(error, '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 private handleError(error: any, from: string): CognitoAuthSession {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\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;AAQ5C,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;QACD,IAAI;YACF,MAAM,OAAO,GAAG,MAAM,IAAI,CAAC,gBAAgB,EAAE,CAAC;Y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AAG,GAAuB;YAC9B,WAAW,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,WAAW,EAAE;YACxD,OAAO,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,UAAU,GAAG,WAAW,EAAE;YAChD,UAAU,EAAE,UAAU;YACtB,YAAY,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,eAAe,GAAG,QAAQ,EAAE;YACvD,SAAS,EAAE,WAAW,aAAX,WAAW,uBAAX,WAAW,CAAE,cAAc,GAAG,aAAa,GAAG,UAAU;YACnE,MAAM,EAAE,WAAW;gBACjB,CAAC,CAAC,8BAA8B,CAAC,EAAE;gBACnC,CAAC,CAAC,8BAA8B,CAAC,EAAE;SACtC,CAAC;QACF,OAAO,GAAG,CAAC;IACb,CAAC;IAEO,WAAW,CAAC,KAAU,EAAE,IAAY;QAC1C,OAAO,CAAC,KAAK,CAAC,wCAAwC,IAAI,IAAI,EAAE,KAAK,CAAC,CAAC;QACvE,MAAM,GAAG,GAAuB;YAC9B,MAAM,EAAE,8BAA8B,CAAC,EAAE;SAC1C,CAAC;QACF,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;YAC7B,OAAO,GAAG,CAAC;SACZ;QACD,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;YACvC,GAAG,CAAC,MAAM,GAAG,8BAA8B,CAAC,SAAS,CAAC;SACvD;QACD,OAAO,GAAG,CAAC;IACb,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 AuthUserAttributeKey,\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 session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 } catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n\n await Auth.federatedSignIn(options as FederatedSignInOptions);\n return this.fetchAuthSession();\n } catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\n }\n\n async fetchAuthSession(): Promise<CognitoAuthSession> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = 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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n\n async getUserAttributes(): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n userAttributes: Record<string, string>;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes:\n attributes?.reduce(\n (acc, data) => ({ ...acc, [data.Name]: data.Value }),\n {},\n ) || {},\n });\n return;\n });\n });\n } catch (error) {\n return {\n ...this.handleError(error, 'getUserAttributes'),\n userAttributes: {},\n };\n }\n }\n\n async updateUserAttributes(options: {\n attributes: { name: AuthUserAttributeKey | string; value: string }[];\n }): Promise<{\n status: AwsAmplifyPluginResponseStatus;\n }> {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user: CognitoUser = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.updateAttributes(\n options.attributes.map(({ name, value }) => ({\n Name: name,\n Value: value,\n })),\n (error, _, metadata) => {\n console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n },\n );\n });\n } catch (error) {\n return {\n ...this.handleError(error, 'updateUserAttributes'),\n };\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(error => this.handleError(error, '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 private handleError(error: any, from: string): CognitoAuthSession {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res: CognitoAuthSession = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -20,6 +20,35 @@ exports.CognitoHostedUIIdentityProvider = void 0;
|
|
|
20
20
|
CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
|
|
21
21
|
CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
|
|
22
22
|
})(exports.CognitoHostedUIIdentityProvider || (exports.CognitoHostedUIIdentityProvider = {}));
|
|
23
|
+
exports.AuthUserAttributeKey = void 0;
|
|
24
|
+
(function (AuthUserAttributeKey) {
|
|
25
|
+
/// Attribute key for user's address
|
|
26
|
+
AuthUserAttributeKey["address"] = "address";
|
|
27
|
+
/// Attribute key for user's birthdate
|
|
28
|
+
AuthUserAttributeKey["birthDate"] = "birthDate";
|
|
29
|
+
/// Attribute key for user's email
|
|
30
|
+
AuthUserAttributeKey["email"] = "email";
|
|
31
|
+
/// Attribute key for user's family name
|
|
32
|
+
AuthUserAttributeKey["familyName"] = "familyName";
|
|
33
|
+
/// Attribute key for user's gender
|
|
34
|
+
AuthUserAttributeKey["gender"] = "gender";
|
|
35
|
+
/// Attribute key for user's given name
|
|
36
|
+
AuthUserAttributeKey["givenName"] = "givenName";
|
|
37
|
+
/// Attribute key for user's locale
|
|
38
|
+
AuthUserAttributeKey["locale"] = "locale";
|
|
39
|
+
/// Attribute key for user's middle name
|
|
40
|
+
AuthUserAttributeKey["middleName"] = "middleName";
|
|
41
|
+
/// Attribute key for user's name
|
|
42
|
+
AuthUserAttributeKey["name"] = "name";
|
|
43
|
+
/// Attribute key for user's nickname
|
|
44
|
+
AuthUserAttributeKey["nickname"] = "nickname";
|
|
45
|
+
/// Attribute key for user's phone number
|
|
46
|
+
AuthUserAttributeKey["phoneNumber"] = "phoneNumber";
|
|
47
|
+
/// Attribute key for user's picture
|
|
48
|
+
AuthUserAttributeKey["picture"] = "picture";
|
|
49
|
+
/// Attribute key for user's preferred user name
|
|
50
|
+
AuthUserAttributeKey["preferredUsername"] = "preferredUsername";
|
|
51
|
+
})(exports.AuthUserAttributeKey || (exports.AuthUserAttributeKey = {}));
|
|
23
52
|
|
|
24
53
|
const AwsAmplify = core.registerPlugin('AwsAmplify', {
|
|
25
54
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AwsAmplifyWeb()),
|
|
@@ -99,6 +128,33 @@ class AwsAmplifyWeb extends core.WebPlugin {
|
|
|
99
128
|
return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });
|
|
100
129
|
}
|
|
101
130
|
}
|
|
131
|
+
async updateUserAttributes(options) {
|
|
132
|
+
if (!this.cognitoConfig) {
|
|
133
|
+
throw new Error('call load first');
|
|
134
|
+
}
|
|
135
|
+
try {
|
|
136
|
+
const user = await awsAmplify.Auth.currentAuthenticatedUser();
|
|
137
|
+
return new Promise((resolve, reject) => {
|
|
138
|
+
user.updateAttributes(options.attributes.map(({ name, value }) => ({
|
|
139
|
+
Name: name,
|
|
140
|
+
Value: value,
|
|
141
|
+
})), (error, _, metadata) => {
|
|
142
|
+
console.log('FROM updateUserAttributes', metadata);
|
|
143
|
+
if (error) {
|
|
144
|
+
reject(error);
|
|
145
|
+
return;
|
|
146
|
+
}
|
|
147
|
+
resolve({
|
|
148
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ok,
|
|
149
|
+
});
|
|
150
|
+
return;
|
|
151
|
+
});
|
|
152
|
+
});
|
|
153
|
+
}
|
|
154
|
+
catch (error) {
|
|
155
|
+
return Object.assign({}, this.handleError(error, 'updateUserAttributes'));
|
|
156
|
+
}
|
|
157
|
+
}
|
|
102
158
|
async signOut() {
|
|
103
159
|
if (!this.cognitoConfig) {
|
|
104
160
|
throw new Error('call load first');
|
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 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 session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\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(error => this.handleError(error, '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 handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\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,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACnG,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC;AACnG,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,I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kBA,sCAA8B,CAAC,EAAE;AACnD,kBAAkBA,sCAA8B,CAAC,EAAE;AACnD,SAAS,CAAC;AACV,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE;AAC7B,QAAQ,OAAO,CAAC,KAAK,CAAC,CAAC,qCAAqC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/E,QAAQ,MAAM,GAAG,GAAG;AACpB,YAAY,MAAM,EAAEA,sCAA8B,CAAC,EAAE;AACrD,SAAS,CAAC;AACV,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACvC,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;AAClE,SAAS;AACT,QAAQ,OAAO,GAAG,CAAC;AACnB,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[\"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 = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\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 session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: name,\n Value: value,\n })), (error, _, metadata) => {\n console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign({}, this.handleError(error, 'updateUserAttributes'));\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(error => this.handleError(error, '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 handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUserAttributeKey","registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AAAWA,gDAA+B;AAC1C,CAAC,UAAU,8BAA8B,EAAE;AAC3C,IAAI,8BAA8B,CAAC,8BAA8B,CAAC,IAAI,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AAe,EAAE,CAAC,QAAQ,EAAE;AAC5H,YAAY,SAAS,EAAE,WAAW,KAAK,IAAI,IAAI,WAAW,KAAK,KAAK,CAAC,GAAG,KAAK,CAAC,GAAG,WAAW,CAAC,cAAc,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,IAAI,WAAW,CAAC,KAAK,EAAE,IAAI,EAAE;AAC7B,QAAQ,OAAO,CAAC,KAAK,CAAC,CAAC,qCAAqC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;AAC/E,QAAQ,MAAM,GAAG,GAAG;AACpB,YAAY,MAAM,EAAEA,sCAA8B,CAAC,EAAE;AACrD,SAAS,CAAC;AACV,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;AACvC,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;AACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;AAClE,SAAS;AACT,QAAQ,OAAO,GAAG,CAAC;AACnB,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -16,6 +16,35 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
|
|
|
16
16
|
CognitoHostedUIIdentityProvider["Amazon"] = "LoginWithAmazon";
|
|
17
17
|
CognitoHostedUIIdentityProvider["Apple"] = "SignInWithApple";
|
|
18
18
|
})(exports.CognitoHostedUIIdentityProvider || (exports.CognitoHostedUIIdentityProvider = {}));
|
|
19
|
+
exports.AuthUserAttributeKey = void 0;
|
|
20
|
+
(function (AuthUserAttributeKey) {
|
|
21
|
+
/// Attribute key for user's address
|
|
22
|
+
AuthUserAttributeKey["address"] = "address";
|
|
23
|
+
/// Attribute key for user's birthdate
|
|
24
|
+
AuthUserAttributeKey["birthDate"] = "birthDate";
|
|
25
|
+
/// Attribute key for user's email
|
|
26
|
+
AuthUserAttributeKey["email"] = "email";
|
|
27
|
+
/// Attribute key for user's family name
|
|
28
|
+
AuthUserAttributeKey["familyName"] = "familyName";
|
|
29
|
+
/// Attribute key for user's gender
|
|
30
|
+
AuthUserAttributeKey["gender"] = "gender";
|
|
31
|
+
/// Attribute key for user's given name
|
|
32
|
+
AuthUserAttributeKey["givenName"] = "givenName";
|
|
33
|
+
/// Attribute key for user's locale
|
|
34
|
+
AuthUserAttributeKey["locale"] = "locale";
|
|
35
|
+
/// Attribute key for user's middle name
|
|
36
|
+
AuthUserAttributeKey["middleName"] = "middleName";
|
|
37
|
+
/// Attribute key for user's name
|
|
38
|
+
AuthUserAttributeKey["name"] = "name";
|
|
39
|
+
/// Attribute key for user's nickname
|
|
40
|
+
AuthUserAttributeKey["nickname"] = "nickname";
|
|
41
|
+
/// Attribute key for user's phone number
|
|
42
|
+
AuthUserAttributeKey["phoneNumber"] = "phoneNumber";
|
|
43
|
+
/// Attribute key for user's picture
|
|
44
|
+
AuthUserAttributeKey["picture"] = "picture";
|
|
45
|
+
/// Attribute key for user's preferred user name
|
|
46
|
+
AuthUserAttributeKey["preferredUsername"] = "preferredUsername";
|
|
47
|
+
})(exports.AuthUserAttributeKey || (exports.AuthUserAttributeKey = {}));
|
|
19
48
|
|
|
20
49
|
const AwsAmplify = core.registerPlugin('AwsAmplify', {
|
|
21
50
|
web: () => Promise.resolve().then(function () { return web; }).then(m => new m.AwsAmplifyWeb()),
|
|
@@ -95,6 +124,33 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
|
|
|
95
124
|
return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });
|
|
96
125
|
}
|
|
97
126
|
}
|
|
127
|
+
async updateUserAttributes(options) {
|
|
128
|
+
if (!this.cognitoConfig) {
|
|
129
|
+
throw new Error('call load first');
|
|
130
|
+
}
|
|
131
|
+
try {
|
|
132
|
+
const user = await awsAmplify.Auth.currentAuthenticatedUser();
|
|
133
|
+
return new Promise((resolve, reject) => {
|
|
134
|
+
user.updateAttributes(options.attributes.map(({ name, value }) => ({
|
|
135
|
+
Name: name,
|
|
136
|
+
Value: value,
|
|
137
|
+
})), (error, _, metadata) => {
|
|
138
|
+
console.log('FROM updateUserAttributes', metadata);
|
|
139
|
+
if (error) {
|
|
140
|
+
reject(error);
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
resolve({
|
|
144
|
+
status: exports.AwsAmplifyPluginResponseStatus.Ok,
|
|
145
|
+
});
|
|
146
|
+
return;
|
|
147
|
+
});
|
|
148
|
+
});
|
|
149
|
+
}
|
|
150
|
+
catch (error) {
|
|
151
|
+
return Object.assign({}, this.handleError(error, 'updateUserAttributes'));
|
|
152
|
+
}
|
|
153
|
+
}
|
|
98
154
|
async signOut() {
|
|
99
155
|
if (!this.cognitoConfig) {
|
|
100
156
|
throw new Error('call load first');
|
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 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 session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\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(error => this.handleError(error, '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 handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["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IACvC,YAAY,OAAO,GAAG,CAAC;IACvB,SAAS;IACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;IACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;IAClE,SAAS;IACT,QAAQ,OAAO,GAAG,CAAC;IACnB,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[\"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 = {}));\nexport var AuthUserAttributeKey;\n(function (AuthUserAttributeKey) {\n /// Attribute key for user's address\n AuthUserAttributeKey[\"address\"] = \"address\";\n /// Attribute key for user's birthdate\n AuthUserAttributeKey[\"birthDate\"] = \"birthDate\";\n /// Attribute key for user's email\n AuthUserAttributeKey[\"email\"] = \"email\";\n /// Attribute key for user's family name\n AuthUserAttributeKey[\"familyName\"] = \"familyName\";\n /// Attribute key for user's gender\n AuthUserAttributeKey[\"gender\"] = \"gender\";\n /// Attribute key for user's given name\n AuthUserAttributeKey[\"givenName\"] = \"givenName\";\n /// Attribute key for user's locale\n AuthUserAttributeKey[\"locale\"] = \"locale\";\n /// Attribute key for user's middle name\n AuthUserAttributeKey[\"middleName\"] = \"middleName\";\n /// Attribute key for user's name\n AuthUserAttributeKey[\"name\"] = \"name\";\n /// Attribute key for user's nickname\n AuthUserAttributeKey[\"nickname\"] = \"nickname\";\n /// Attribute key for user's phone number\n AuthUserAttributeKey[\"phoneNumber\"] = \"phoneNumber\";\n /// Attribute key for user's picture\n AuthUserAttributeKey[\"picture\"] = \"picture\";\n /// Attribute key for user's preferred user name\n AuthUserAttributeKey[\"preferredUsername\"] = \"preferredUsername\";\n})(AuthUserAttributeKey || (AuthUserAttributeKey = {}));\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 session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\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 catch (error) {\n return this.handleError(error, 'signIn');\n }\n }\n async federatedSignIn(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const session = await this.fetchAuthSession();\n if (session.status === AwsAmplifyPluginResponseStatus.Ok) {\n return session;\n }\n await Auth.federatedSignIn(options);\n return this.fetchAuthSession();\n }\n catch (error) {\n return this.handleError(error, 'federatedSignIn');\n }\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 return this.handleError(error, 'fetchAuthSession');\n }\n }\n async getUserAttributes() {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.getUserAttributes((error, attributes) => {\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n userAttributes: (attributes === null || attributes === void 0 ? void 0 : attributes.reduce((acc, data) => (Object.assign(Object.assign({}, acc), { [data.Name]: data.Value })), {})) || {},\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign(Object.assign({}, this.handleError(error, 'getUserAttributes')), { userAttributes: {} });\n }\n }\n async updateUserAttributes(options) {\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n try {\n const user = await Auth.currentAuthenticatedUser();\n return new Promise((resolve, reject) => {\n user.updateAttributes(options.attributes.map(({ name, value }) => ({\n Name: name,\n Value: value,\n })), (error, _, metadata) => {\n console.log('FROM updateUserAttributes', metadata);\n if (error) {\n reject(error);\n return;\n }\n resolve({\n status: AwsAmplifyPluginResponseStatus.Ok,\n });\n return;\n });\n });\n }\n catch (error) {\n return Object.assign({}, this.handleError(error, 'updateUserAttributes'));\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(error => this.handleError(error, '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 handleError(error, from) {\n console.error(`[CAPACITOR AWS AMPLIFY] - error from ${from}: `, error);\n const res = {\n status: AwsAmplifyPluginResponseStatus.Ko,\n };\n if (typeof error !== 'string') {\n return res;\n }\n if (error.includes('not authenticated')) {\n res.status = AwsAmplifyPluginResponseStatus.SignedOut;\n }\n return res;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["AwsAmplifyPluginResponseStatus","CognitoHostedUIIdentityProvider","AuthUserAttributeKey","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,sCAA8B,GAAG,EAAE,CAAC,CAAC,CAAC;AACjEC,qDAAgC;IAC3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AK,CAAC,CAAC,qCAAqC,EAAE,IAAI,CAAC,EAAE,CAAC,EAAE,KAAK,CAAC,CAAC;IAC/E,QAAQ,MAAM,GAAG,GAAG;IACpB,YAAY,MAAM,EAAEA,sCAA8B,CAAC,EAAE;IACrD,SAAS,CAAC;IACV,QAAQ,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE;IACvC,YAAY,OAAO,GAAG,CAAC;IACvB,SAAS;IACT,QAAQ,IAAI,KAAK,CAAC,QAAQ,CAAC,mBAAmB,CAAC,EAAE;IACjD,YAAY,GAAG,CAAC,MAAM,GAAGA,sCAA8B,CAAC,SAAS,CAAC;IAClE,SAAS;IACT,QAAQ,OAAO,GAAG,CAAC;IACnB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -9,15 +9,15 @@ import AWSMobileClient
|
|
|
9
9
|
private let TAG = "[Capacitor AwsAmplify]"
|
|
10
10
|
|
|
11
11
|
private var isLoaded = false
|
|
12
|
-
// static public let instance = AwsAmplify()
|
|
12
|
+
// static public let instance = AwsAmplify()
|
|
13
|
+
|
|
14
|
+
// private let sessionSubject = BehaviorSubject<Optional<AuthSession>>(value: nil)
|
|
15
|
+
// public var isLoggedIn$: Observable<Bool> {
|
|
16
|
+
// sessionSubject.map { session in
|
|
17
|
+
// session != nil
|
|
18
|
+
// }
|
|
19
|
+
// }
|
|
13
20
|
|
|
14
|
-
// private let sessionSubject = BehaviorSubject<Optional<AuthSession>>(value: nil)
|
|
15
|
-
// public var isLoggedIn$: Observable<Bool> {
|
|
16
|
-
// sessionSubject.map { session in
|
|
17
|
-
// session != nil
|
|
18
|
-
// }
|
|
19
|
-
// }
|
|
20
|
-
|
|
21
21
|
struct AccessTokenPayload: Decodable {
|
|
22
22
|
var device_key:String
|
|
23
23
|
}
|
|
@@ -27,8 +27,8 @@ import AWSMobileClient
|
|
|
27
27
|
}
|
|
28
28
|
|
|
29
29
|
public func load(cognitoConfig: JSObject,
|
|
30
|
-
|
|
31
|
-
|
|
30
|
+
onSuccess: @escaping () -> (),
|
|
31
|
+
onError: @escaping (any Error) -> ()) {
|
|
32
32
|
initAwsService(cognitoConfig: cognitoConfig, onSuccess: onSuccess, onError: onError)
|
|
33
33
|
}
|
|
34
34
|
|
|
@@ -73,7 +73,7 @@ import AWSMobileClient
|
|
|
73
73
|
|
|
74
74
|
DispatchQueue.main.async {
|
|
75
75
|
Amplify.Auth.signInWithWebUI(for: authProvider,
|
|
76
|
-
|
|
76
|
+
presentationAnchor: UIApplication.shared.windows.first!, options: .preferPrivateSession()) { result in
|
|
77
77
|
var ret: JSObject = [:]
|
|
78
78
|
switch result {
|
|
79
79
|
case .success(_):
|
|
@@ -86,12 +86,12 @@ import AWSMobileClient
|
|
|
86
86
|
ret["status"] = -2
|
|
87
87
|
default:
|
|
88
88
|
ret["status"] = -1
|
|
89
|
-
}
|
|
89
|
+
}
|
|
90
90
|
onSuccess(ret)
|
|
91
91
|
}
|
|
92
92
|
}
|
|
93
93
|
}
|
|
94
|
-
|
|
94
|
+
|
|
95
95
|
}
|
|
96
96
|
|
|
97
97
|
public func signOut(
|
|
@@ -102,14 +102,14 @@ import AWSMobileClient
|
|
|
102
102
|
var ret: JSObject = [:]
|
|
103
103
|
|
|
104
104
|
switch result {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
105
|
+
case .success:
|
|
106
|
+
ret["status"] = 0
|
|
107
|
+
onSuccess(ret)
|
|
108
|
+
case .failure(let authError):
|
|
109
|
+
print("\(self.TAG) Sign out failed with error \(authError)")
|
|
110
|
+
ret["status"] = -1
|
|
111
|
+
onSuccess(ret)
|
|
112
|
+
}
|
|
113
113
|
}
|
|
114
114
|
}
|
|
115
115
|
|
|
@@ -121,7 +121,7 @@ import AWSMobileClient
|
|
|
121
121
|
do {
|
|
122
122
|
let session = try result.get()
|
|
123
123
|
var ret: JSObject = [:]
|
|
124
|
-
|
|
124
|
+
|
|
125
125
|
// Get user sub or identity id
|
|
126
126
|
if let identityProvider = session as? AuthCognitoIdentityProvider {
|
|
127
127
|
let usersub = try identityProvider.getUserSub().get()
|
|
@@ -130,13 +130,13 @@ import AWSMobileClient
|
|
|
130
130
|
|
|
131
131
|
ret["identityId"] = identityId
|
|
132
132
|
}
|
|
133
|
-
|
|
133
|
+
|
|
134
134
|
// Get AWS credentials
|
|
135
135
|
// if let awsCredentialsProvider = session as? AuthAWSCredentialsProvider {
|
|
136
136
|
// let credentials = try awsCredentialsProvider.getAWSCredentials().get()
|
|
137
137
|
// print("Access key - \(credentials.accessKey) ")
|
|
138
138
|
// }
|
|
139
|
-
|
|
139
|
+
|
|
140
140
|
// Get cognito user pool token
|
|
141
141
|
if let cognitoTokenProvider = session as? AuthCognitoTokensProvider {
|
|
142
142
|
let tokens = try cognitoTokenProvider.getCognitoTokens().get()
|
|
@@ -148,27 +148,27 @@ import AWSMobileClient
|
|
|
148
148
|
|
|
149
149
|
// Retrieve the device key from the payload of access token
|
|
150
150
|
let accessToken = tokens.accessToken as NSString
|
|
151
|
-
// print("\(self.TAG) accessToken - \(tokens.idToken) ")
|
|
151
|
+
// print("\(self.TAG) accessToken - \(tokens.idToken) ")
|
|
152
152
|
let chunks = accessToken.components(separatedBy: ".")
|
|
153
153
|
let accessTokenPayload = self.decodeJWTPart(part: chunks[1])
|
|
154
154
|
let deviceKey = accessTokenPayload?.device_key
|
|
155
|
-
|
|
155
|
+
|
|
156
156
|
ret["deviceKey"] = deviceKey
|
|
157
157
|
ret["status"] = 0
|
|
158
158
|
} else {
|
|
159
159
|
ret["status"] = -1
|
|
160
160
|
}
|
|
161
161
|
|
|
162
|
-
// self.sessionSubject.onNext(session)
|
|
162
|
+
// self.sessionSubject.onNext(session)
|
|
163
163
|
|
|
164
164
|
print("\(self.TAG) - Fetch Auth Session successfully")
|
|
165
|
-
// print("\(self.TAG) - \(ret)")
|
|
165
|
+
// print("\(self.TAG) - \(ret)")
|
|
166
166
|
onSuccess(ret)
|
|
167
167
|
} catch {
|
|
168
168
|
var ret: JSObject = [:]
|
|
169
169
|
ret["status"] = -1
|
|
170
170
|
if let authError = error as? AuthError
|
|
171
|
-
|
|
171
|
+
{
|
|
172
172
|
let cognitoAuthError = authError
|
|
173
173
|
switch cognitoAuthError {
|
|
174
174
|
case .signedOut:
|
|
@@ -177,7 +177,7 @@ import AWSMobileClient
|
|
|
177
177
|
ret["status"] = -1
|
|
178
178
|
}
|
|
179
179
|
}
|
|
180
|
-
|
|
180
|
+
|
|
181
181
|
onSuccess(ret)
|
|
182
182
|
print("\(self.TAG) Fetch auth session failed with error - \(error)")
|
|
183
183
|
}
|
|
@@ -206,7 +206,7 @@ import AWSMobileClient
|
|
|
206
206
|
} catch {
|
|
207
207
|
ret["status"] = -1
|
|
208
208
|
if let authError = error as? AuthError
|
|
209
|
-
|
|
209
|
+
{
|
|
210
210
|
let cognitoAuthError = authError
|
|
211
211
|
switch cognitoAuthError {
|
|
212
212
|
case .signedOut:
|
|
@@ -221,6 +221,38 @@ import AWSMobileClient
|
|
|
221
221
|
}
|
|
222
222
|
}
|
|
223
223
|
|
|
224
|
+
public func updateUserAttributes(
|
|
225
|
+
userAttributes: [AuthUserAttribute],
|
|
226
|
+
onSuccess: @escaping (JSObject) -> (),
|
|
227
|
+
onError: @escaping (any Error) -> ()
|
|
228
|
+
) {
|
|
229
|
+
var ret: JSObject = [:]
|
|
230
|
+
Amplify.Auth.update(userAttributes: userAttributes) { result in
|
|
231
|
+
do {
|
|
232
|
+
let attributes = try result.get()
|
|
233
|
+
|
|
234
|
+
ret["status"] = 0
|
|
235
|
+
|
|
236
|
+
print("\(self.TAG) - update user attributes successfully")
|
|
237
|
+
onSuccess(ret)
|
|
238
|
+
} catch {
|
|
239
|
+
ret["status"] = -1
|
|
240
|
+
if let authError = error as? AuthError
|
|
241
|
+
{
|
|
242
|
+
let cognitoAuthError = authError
|
|
243
|
+
switch cognitoAuthError {
|
|
244
|
+
case .signedOut:
|
|
245
|
+
ret["status"] = -3
|
|
246
|
+
default:
|
|
247
|
+
ret["status"] = -1
|
|
248
|
+
}
|
|
249
|
+
}
|
|
250
|
+
onSuccess(ret)
|
|
251
|
+
print("\(self.TAG) update user attributes failed with error - \(error)")
|
|
252
|
+
}
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
|
|
224
256
|
public func getCurrentUser() -> AuthUser {
|
|
225
257
|
return Amplify.Auth.getCurrentUser()!
|
|
226
258
|
}
|
|
@@ -234,7 +266,7 @@ import AWSMobileClient
|
|
|
234
266
|
}
|
|
235
267
|
return stringTobeEncoded
|
|
236
268
|
}
|
|
237
|
-
|
|
269
|
+
|
|
238
270
|
func decodeJWTPart(part: String) -> AccessTokenPayload? {
|
|
239
271
|
let payloadPaddingString = base64StringWithPadding(encodedString: part)
|
|
240
272
|
guard let payloadData = Data(base64Encoded: payloadPaddingString) else {
|
|
@@ -307,38 +339,38 @@ import AWSMobileClient
|
|
|
307
339
|
Amplify.Hub.listen(to: .auth) { payload in
|
|
308
340
|
|
|
309
341
|
switch payload.eventName {
|
|
310
|
-
|
|
342
|
+
case HubPayload.EventName.Auth.signedIn:
|
|
311
343
|
print("\(self.TAG) User signed in")
|
|
312
344
|
// Update UI
|
|
313
345
|
break
|
|
314
346
|
|
|
315
|
-
|
|
347
|
+
case HubPayload.EventName.Auth.sessionExpired:
|
|
316
348
|
print("\(self.TAG) Session expired")
|
|
317
|
-
|
|
349
|
+
// Re-authenticate the user
|
|
318
350
|
break
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
// self.sessionSubject.onNext(nil)
|
|
351
|
+
|
|
352
|
+
case HubPayload.EventName.Auth.signedOut:
|
|
353
|
+
// self.sessionSubject.onNext(nil)
|
|
322
354
|
print("\(self.TAG) User signed out")
|
|
323
|
-
|
|
355
|
+
// Update UI
|
|
324
356
|
break
|
|
325
|
-
|
|
326
|
-
|
|
357
|
+
|
|
358
|
+
case HubPayload.EventName.Auth.userDeleted:
|
|
327
359
|
print("\(self.TAG) User deleted")
|
|
328
|
-
|
|
360
|
+
// Update UI
|
|
329
361
|
break
|
|
330
362
|
|
|
331
|
-
|
|
363
|
+
case HubPayload.EventName.Auth.socialWebUISignInAPI:
|
|
332
364
|
print("\(self.TAG) Social login")
|
|
333
|
-
// self.fetchAuthSession { _ in } onError: { _ in }
|
|
334
|
-
|
|
365
|
+
// self.fetchAuthSession { _ in } onError: { _ in }
|
|
366
|
+
|
|
367
|
+
break
|
|
368
|
+
|
|
369
|
+
default:
|
|
335
370
|
break
|
|
336
|
-
|
|
337
|
-
default:
|
|
338
|
-
break
|
|
339
371
|
}
|
|
340
372
|
|
|
341
|
-
// print("\(self.TAG) Amplify.Hub.listen \(payload)")
|
|
373
|
+
// print("\(self.TAG) Amplify.Hub.listen \(payload)")
|
|
342
374
|
}
|
|
343
375
|
onSuccess()
|
|
344
376
|
} catch {
|
|
@@ -347,14 +379,14 @@ import AWSMobileClient
|
|
|
347
379
|
}
|
|
348
380
|
}
|
|
349
381
|
|
|
350
|
-
// public func getSession() -> Optional<AuthSession> {
|
|
351
|
-
// do {
|
|
352
|
-
// return try self.sessionSubject.value()
|
|
353
|
-
// } catch {
|
|
354
|
-
// return nil
|
|
355
|
-
// }
|
|
356
|
-
// }
|
|
357
|
-
|
|
382
|
+
// public func getSession() -> Optional<AuthSession> {
|
|
383
|
+
// do {
|
|
384
|
+
// return try self.sessionSubject.value()
|
|
385
|
+
// } catch {
|
|
386
|
+
// return nil
|
|
387
|
+
// }
|
|
388
|
+
// }
|
|
389
|
+
|
|
358
390
|
// public func hasFullRegistration() -> Observable<Bool> {
|
|
359
391
|
// return Observable.create { observer in
|
|
360
392
|
// AWSMobileClient.default().getUserAttributes { (userAttributes, error) in
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Amplify
|
|
2
3
|
import Capacitor
|
|
3
4
|
|
|
4
5
|
/**
|
|
@@ -8,7 +9,7 @@ import Capacitor
|
|
|
8
9
|
@objc(AwsAmplifyPlugin)
|
|
9
10
|
public class AwsAmplifyPlugin: CAPPlugin {
|
|
10
11
|
private let implementation = AwsAmplify()
|
|
11
|
-
|
|
12
|
+
|
|
12
13
|
@objc func load(_ call: CAPPluginCall) {
|
|
13
14
|
let cognitoConfig = call.getObject("cognitoConfig")!
|
|
14
15
|
|
|
@@ -22,7 +23,7 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
22
23
|
call.reject(error.localizedDescription)
|
|
23
24
|
})
|
|
24
25
|
}
|
|
25
|
-
|
|
26
|
+
|
|
26
27
|
@objc func signIn(_ call: CAPPluginCall) {
|
|
27
28
|
let email = call.getString("email") ?? ""
|
|
28
29
|
let password = call.getString("password") ?? ""
|
|
@@ -48,10 +49,10 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
48
49
|
@objc func signOut(_ call: CAPPluginCall) {
|
|
49
50
|
self.implementation.signOut(
|
|
50
51
|
onSuccess: { response in
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
52
|
+
call.resolve(response)
|
|
53
|
+
}, onError: { error in
|
|
54
|
+
call.reject(error.localizedDescription)
|
|
55
|
+
})
|
|
55
56
|
}
|
|
56
57
|
|
|
57
58
|
@objc func federatedSignIn(_ call: CAPPluginCall) {
|
|
@@ -85,27 +86,78 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
85
86
|
|
|
86
87
|
}
|
|
87
88
|
@objc func fetchAuthSession(_ call: CAPPluginCall) {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
89
|
+
|
|
90
|
+
self.implementation.fetchAuthSession(
|
|
91
|
+
onSuccess: {session in
|
|
92
|
+
call.resolve(session)
|
|
93
|
+
},
|
|
94
|
+
onError: {error in
|
|
95
|
+
call.reject(error.localizedDescription)
|
|
96
|
+
})
|
|
96
97
|
}
|
|
97
98
|
|
|
98
99
|
@objc func getUserAttributes(_ call: CAPPluginCall) {
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
|
|
101
|
+
self.implementation.getUserAttributes(
|
|
102
|
+
onSuccess: {session in
|
|
103
|
+
call.resolve(session)
|
|
104
|
+
},
|
|
105
|
+
onError: {error in
|
|
106
|
+
call.reject(error.localizedDescription)
|
|
107
|
+
})
|
|
107
108
|
}
|
|
108
|
-
|
|
109
|
+
|
|
110
|
+
@objc func updateUserAttributes(_ call: CAPPluginCall) {
|
|
111
|
+
|
|
112
|
+
if let userAttributes = call.getArray("attributes") as JSArray?{
|
|
113
|
+
self.implementation.updateUserAttributes(
|
|
114
|
+
userAttributes: userAttributes.map {
|
|
115
|
+
let attribute = $0 as! JSObject
|
|
116
|
+
return AuthUserAttribute(getAttributeKey(key: attribute["name"] as! String), value: attribute["value"] as! String)
|
|
117
|
+
},
|
|
118
|
+
onSuccess: {session in
|
|
119
|
+
call.resolve(session)
|
|
120
|
+
},
|
|
121
|
+
onError: {error in
|
|
122
|
+
call.reject(error.localizedDescription)
|
|
123
|
+
})
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
private func getAttributeKey(key: String) -> AuthUserAttributeKey{
|
|
129
|
+
switch(key){
|
|
130
|
+
case "address":
|
|
131
|
+
return AuthUserAttributeKey.address
|
|
132
|
+
case "birthDate":
|
|
133
|
+
return AuthUserAttributeKey.birthDate
|
|
134
|
+
case "email":
|
|
135
|
+
return AuthUserAttributeKey.email
|
|
136
|
+
case "familyName":
|
|
137
|
+
return AuthUserAttributeKey.familyName
|
|
138
|
+
case "gender":
|
|
139
|
+
return AuthUserAttributeKey.gender
|
|
140
|
+
case "givenName":
|
|
141
|
+
return AuthUserAttributeKey.givenName
|
|
142
|
+
case "locale":
|
|
143
|
+
return AuthUserAttributeKey.locale
|
|
144
|
+
case "middleName":
|
|
145
|
+
return AuthUserAttributeKey.middleName
|
|
146
|
+
case "name":
|
|
147
|
+
return AuthUserAttributeKey.name
|
|
148
|
+
case "nickname":
|
|
149
|
+
return AuthUserAttributeKey.nickname
|
|
150
|
+
case "phoneNumber":
|
|
151
|
+
return AuthUserAttributeKey.phoneNumber
|
|
152
|
+
case "picture":
|
|
153
|
+
return AuthUserAttributeKey.picture
|
|
154
|
+
case "preferredUsername":
|
|
155
|
+
return AuthUserAttributeKey.preferredUsername
|
|
156
|
+
default:
|
|
157
|
+
return AuthUserAttributeKey.custom(key)
|
|
158
|
+
}
|
|
159
|
+
}
|
|
160
|
+
|
|
109
161
|
// var permissionCallID: String?
|
|
110
162
|
// var locationManager: CLLocationManager?
|
|
111
163
|
|