@falconeta/capacitor-aws-amplify 0.0.2 → 0.0.4
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 +26 -0
- package/dist/docs.json +69 -0
- package/dist/esm/definitions.d.ts +17 -0
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +4 -1
- package/dist/esm/web.js +4 -1
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +3 -0
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +3 -0
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AwsAmplify.swift +298 -3
- package/ios/Plugin/AwsAmplifyPlugin.m +1 -0
- package/ios/Plugin/AwsAmplifyPlugin.swift +27 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,6 +13,7 @@ npx cap sync
|
|
|
13
13
|
|
|
14
14
|
<docgen-index>
|
|
15
15
|
|
|
16
|
+
* [`load(...)`](#load)
|
|
16
17
|
* [`signIn(...)`](#signin)
|
|
17
18
|
* [`federatedSignIn(...)`](#federatedsignin)
|
|
18
19
|
* [`signOut()`](#signout)
|
|
@@ -23,6 +24,19 @@ npx cap sync
|
|
|
23
24
|
<docgen-api>
|
|
24
25
|
<!--Update the source file JSDoc comments and rerun docgen to update the docs below-->
|
|
25
26
|
|
|
27
|
+
### load(...)
|
|
28
|
+
|
|
29
|
+
```typescript
|
|
30
|
+
load(options: { cognitoConfig: AWSCognitoConfig; }) => Promise<void>
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
| Param | Type |
|
|
34
|
+
| ------------- | --------------------------------------------------------------------------------- |
|
|
35
|
+
| **`options`** | <code>{ cognitoConfig: <a href="#awscognitoconfig">AWSCognitoConfig</a>; }</code> |
|
|
36
|
+
|
|
37
|
+
--------------------
|
|
38
|
+
|
|
39
|
+
|
|
26
40
|
### signIn(...)
|
|
27
41
|
|
|
28
42
|
```typescript
|
|
@@ -67,6 +81,18 @@ signOut() => Promise<any>
|
|
|
67
81
|
### Interfaces
|
|
68
82
|
|
|
69
83
|
|
|
84
|
+
#### AWSCognitoConfig
|
|
85
|
+
|
|
86
|
+
| Prop | Type |
|
|
87
|
+
| ---------------------------------- | ------------------------------------------------------------------------------------------------------------------------ |
|
|
88
|
+
| **`aws_cognito_region`** | <code>string</code> |
|
|
89
|
+
| **`aws_user_pools_id`** | <code>string</code> |
|
|
90
|
+
| **`aws_user_pools_web_client_id`** | <code>string</code> |
|
|
91
|
+
| **`aws_cognito_identity_pool_id`** | <code>string</code> |
|
|
92
|
+
| **`aws_mandatory_sign_in`** | <code>string</code> |
|
|
93
|
+
| **`oauth`** | <code>{ domain: string; scope: string[]; redirectSignIn: string; redirectSignOut: string; responseType: 'code'; }</code> |
|
|
94
|
+
|
|
95
|
+
|
|
70
96
|
#### CognitoAuthSession
|
|
71
97
|
|
|
72
98
|
| Prop | Type |
|
package/dist/docs.json
CHANGED
|
@@ -5,6 +5,24 @@
|
|
|
5
5
|
"docs": "",
|
|
6
6
|
"tags": [],
|
|
7
7
|
"methods": [
|
|
8
|
+
{
|
|
9
|
+
"name": "load",
|
|
10
|
+
"signature": "(options: { cognitoConfig: AWSCognitoConfig; }) => Promise<void>",
|
|
11
|
+
"parameters": [
|
|
12
|
+
{
|
|
13
|
+
"name": "options",
|
|
14
|
+
"docs": "",
|
|
15
|
+
"type": "{ cognitoConfig: AWSCognitoConfig; }"
|
|
16
|
+
}
|
|
17
|
+
],
|
|
18
|
+
"returns": "Promise<void>",
|
|
19
|
+
"tags": [],
|
|
20
|
+
"docs": "",
|
|
21
|
+
"complexTypes": [
|
|
22
|
+
"AWSCognitoConfig"
|
|
23
|
+
],
|
|
24
|
+
"slug": "load"
|
|
25
|
+
},
|
|
8
26
|
{
|
|
9
27
|
"name": "signIn",
|
|
10
28
|
"signature": "(options: { email: string; password: string; identityId: string; }) => Promise<CognitoAuthSession>",
|
|
@@ -55,6 +73,57 @@
|
|
|
55
73
|
"properties": []
|
|
56
74
|
},
|
|
57
75
|
"interfaces": [
|
|
76
|
+
{
|
|
77
|
+
"name": "AWSCognitoConfig",
|
|
78
|
+
"slug": "awscognitoconfig",
|
|
79
|
+
"docs": "",
|
|
80
|
+
"tags": [],
|
|
81
|
+
"methods": [],
|
|
82
|
+
"properties": [
|
|
83
|
+
{
|
|
84
|
+
"name": "aws_cognito_region",
|
|
85
|
+
"tags": [],
|
|
86
|
+
"docs": "",
|
|
87
|
+
"complexTypes": [],
|
|
88
|
+
"type": "string"
|
|
89
|
+
},
|
|
90
|
+
{
|
|
91
|
+
"name": "aws_user_pools_id",
|
|
92
|
+
"tags": [],
|
|
93
|
+
"docs": "",
|
|
94
|
+
"complexTypes": [],
|
|
95
|
+
"type": "string"
|
|
96
|
+
},
|
|
97
|
+
{
|
|
98
|
+
"name": "aws_user_pools_web_client_id",
|
|
99
|
+
"tags": [],
|
|
100
|
+
"docs": "",
|
|
101
|
+
"complexTypes": [],
|
|
102
|
+
"type": "string"
|
|
103
|
+
},
|
|
104
|
+
{
|
|
105
|
+
"name": "aws_cognito_identity_pool_id",
|
|
106
|
+
"tags": [],
|
|
107
|
+
"docs": "",
|
|
108
|
+
"complexTypes": [],
|
|
109
|
+
"type": "string"
|
|
110
|
+
},
|
|
111
|
+
{
|
|
112
|
+
"name": "aws_mandatory_sign_in",
|
|
113
|
+
"tags": [],
|
|
114
|
+
"docs": "",
|
|
115
|
+
"complexTypes": [],
|
|
116
|
+
"type": "string"
|
|
117
|
+
},
|
|
118
|
+
{
|
|
119
|
+
"name": "oauth",
|
|
120
|
+
"tags": [],
|
|
121
|
+
"docs": "",
|
|
122
|
+
"complexTypes": [],
|
|
123
|
+
"type": "{ domain: string; scope: string[]; redirectSignIn: string; redirectSignOut: string; responseType: 'code'; }"
|
|
124
|
+
}
|
|
125
|
+
]
|
|
126
|
+
},
|
|
58
127
|
{
|
|
59
128
|
"name": "CognitoAuthSession",
|
|
60
129
|
"slug": "cognitoauthsession",
|
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
export interface AwsAmplifyPlugin {
|
|
2
|
+
load(options: {
|
|
3
|
+
cognitoConfig: AWSCognitoConfig;
|
|
4
|
+
}): Promise<void>;
|
|
2
5
|
signIn(options: {
|
|
3
6
|
email: string;
|
|
4
7
|
password: string;
|
|
@@ -17,3 +20,17 @@ export interface CognitoAuthSession {
|
|
|
17
20
|
refreshToken: string;
|
|
18
21
|
deviceKey: string | null;
|
|
19
22
|
}
|
|
23
|
+
export interface AWSCognitoConfig {
|
|
24
|
+
aws_cognito_region: string;
|
|
25
|
+
aws_user_pools_id: string;
|
|
26
|
+
aws_user_pools_web_client_id: string;
|
|
27
|
+
aws_cognito_identity_pool_id: string;
|
|
28
|
+
aws_mandatory_sign_in: string;
|
|
29
|
+
oauth: {
|
|
30
|
+
domain: string;
|
|
31
|
+
scope: string[];
|
|
32
|
+
redirectSignIn: string;
|
|
33
|
+
redirectSignOut: string;
|
|
34
|
+
responseType: 'code';
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AwsAmplifyPlugin {\n signIn(options: {\n email: string;\n password: string;\n identityId: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: string;\n identityId: string;\n }): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken: string;\n idToken: string;\n identityId: string;\n refreshToken: string;\n deviceKey: string | null;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n identityId: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: string;\n identityId: string;\n }): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken: string;\n idToken: string;\n identityId: string;\n refreshToken: string;\n deviceKey: string | null;\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import type { AwsAmplifyPlugin, CognitoAuthSession } from './definitions';
|
|
2
|
+
import type { AWSCognitoConfig, AwsAmplifyPlugin, CognitoAuthSession } from './definitions';
|
|
3
3
|
export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
|
|
4
|
+
load(options: {
|
|
5
|
+
cognitoConfig: AWSCognitoConfig;
|
|
6
|
+
}): Promise<void>;
|
|
4
7
|
signIn(options: {
|
|
5
8
|
email: string;
|
|
6
9
|
password: string;
|
package/dist/esm/web.js
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import { WebPlugin } from '@capacitor/core';
|
|
2
|
-
import { Auth } from 'aws-amplify';
|
|
2
|
+
import { Amplify, Auth } from 'aws-amplify';
|
|
3
3
|
export class AwsAmplifyWeb extends WebPlugin {
|
|
4
|
+
async load(options) {
|
|
5
|
+
Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
6
|
+
}
|
|
4
7
|
async signIn(options) {
|
|
5
8
|
// console.log(LOG_PREFIX, options);
|
|
6
9
|
return new Promise((resolve, reject) => {
|
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,i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ACnD,IAAI,EACJ,OAAO,CAAC,UAAU,CACnB,CAAC;oBACF,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;gBAC9D,CAAC,CAAC,CAAC;YACL,CAAC,CAAC;iBACD,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;QAC/B,CAAC,CAAC,CAAC;IACL,CAAC;IAED,KAAK,CAAC,OAAO;QACX,OAAO,IAAI,CAAC,OAAO,EAAE,CAAC;IACxB,CAAC;IAEO,qBAAqB,CAAC,IAAiB,EAAE,UAAkB;QACjE,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;QAEhD,IAAI,WAAW,EAAE;YACf,MAAM,GAAG,GAAuB;gBAC9B,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;gBACvD,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;gBAC/C,UAAU,EAAE,UAAU;gBACtB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;gBACtD,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;aACnE,CAAC;YACF,OAAO,GAAG,CAAC;SACZ;QAED,OAAO,IAAI,CAAC;IACd,CAAC;CACF","sourcesContent":["import type { FederatedSignInOptions } from '@aws-amplify/auth/lib/types';\nimport { WebPlugin } from '@capacitor/core';\nimport type { CognitoUser } from 'amazon-cognito-identity-js';\nimport { Amplify, Auth } from 'aws-amplify';\n\nimport type {\n AWSCognitoConfig,\n AwsAmplifyPlugin,\n CognitoAuthSession,\n} from './definitions';\n\nexport class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n identityId: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user: CognitoUser) => {\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n options.identityId,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n\n async federatedSignIn(options: {\n provider: string;\n identityId: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options as FederatedSignInOptions)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n options.identityId,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n\n async signOut(): Promise<any> {\n return Auth.signOut();\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n if (userSession) {\n const res: CognitoAuthSession = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n\n return null;\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -10,6 +10,9 @@ const AwsAmplify = core.registerPlugin('AwsAmplify', {
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
class AwsAmplifyWeb extends core.WebPlugin {
|
|
13
|
+
async load(options) {
|
|
14
|
+
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
15
|
+
}
|
|
13
16
|
async signIn(options) {
|
|
14
17
|
// console.log(LOG_PREFIX, options);
|
|
15
18
|
return new Promise((resolve, reject) => {
|
package/dist/plugin.cjs.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Auth"],"mappings":";;;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,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,OAAO,EAAE,CAAC;AAC9B,KAAK;AACL,IAAI,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE;AAC5C,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;AACxD,QAAQ,IAAI,WAAW,EAAE;AACzB,YAAY,MAAM,GAAG,GAAG;AACxB,gBAAgB,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;AACvE,gBAAgB,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;AAC/D,gBAAgB,UAAU,EAAE,UAAU;AACtC,gBAAgB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;AACtE,gBAAgB,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AAClF,aAAa,CAAC;AACd,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AAC/D,CAAC;;ACDM,MAAM,aAAa,SAASC,cAAS,CAAC;AAC7C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQC,kBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AACpE,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B;AACA,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;AAChD,YAAYC,eAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK;AACxE,gBAAgB,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,OA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,gBAAgB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;AACtE,gBAAgB,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;AAClF,aAAa,CAAC;AACd,YAAY,OAAO,GAAG,CAAC;AACvB,SAAS;AACT,QAAQ,OAAO,IAAI,CAAC;AACpB,KAAK;AACL;;;;;;;;;"}
|
package/dist/plugin.js
CHANGED
|
@@ -6,6 +6,9 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
class AwsAmplifyWeb extends core.WebPlugin {
|
|
9
|
+
async load(options) {
|
|
10
|
+
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
11
|
+
}
|
|
9
12
|
async signIn(options) {
|
|
10
13
|
// console.log(LOG_PREFIX, options);
|
|
11
14
|
return new Promise((resolve, reject) => {
|
package/dist/plugin.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Auth"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC;;ICDM,MAAM,aAAa,SAASC,cAAS,CAAC;IAC7C,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B;IACA,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,KAAK;IAChD,YAAYC,eAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAI,KAAK;IACxE,gBAAgB,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI,EAAE,OAAO,CAAC,UAAU,CAAC,CAAC;IAChG,gBAAgB,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,EAAE,CAAC;IAC5E,aAAa,CAAC,CAAC;IACf,SAAS,CAAC,CAAC;IACX,KAAK;IACL,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;IACnC;IACA,QAAQ,OAAO,IAAI,OAAO,CA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;IACL;;;;;;;;;;;;;;;;;"}
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,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AAC;IAChF,iBAAiB,CAAC,CAAC;IACnB,aAAa,CAAC;IACd,iBAAiB,KAAK,CAAC,GAAG,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,CAAC;IAC3C,SAAS,CAAC,CAAC;IACX,KAAK;IACL,IAAI,MAAM,OAAO,GAAG;IACpB,QAAQ,OAAOA,eAAI,CAAC,OAAO,EAAE,CAAC;IAC9B,KAAK;IACL,IAAI,qBAAqB,CAAC,IAAI,EAAE,UAAU,EAAE;IAC5C,QAAQ,MAAM,WAAW,GAAG,IAAI,CAAC,oBAAoB,EAAE,CAAC;IACxD,QAAQ,IAAI,WAAW,EAAE;IACzB,YAAY,MAAM,GAAG,GAAG;IACxB,gBAAgB,WAAW,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,WAAW,EAAE;IACvE,gBAAgB,OAAO,EAAE,WAAW,CAAC,UAAU,EAAE,CAAC,WAAW,EAAE;IAC/D,gBAAgB,UAAU,EAAE,UAAU;IACtC,gBAAgB,YAAY,EAAE,WAAW,CAAC,eAAe,EAAE,CAAC,QAAQ,EAAE;IACtE,gBAAgB,SAAS,EAAE,WAAW,CAAC,cAAc,EAAE,CAAC,aAAa,EAAE,CAAC,UAAU;IAClF,aAAa,CAAC;IACd,YAAY,OAAO,GAAG,CAAC;IACvB,SAAS;IACT,QAAQ,OAAO,IAAI,CAAC;IACpB,KAAK;IACL;;;;;;;;;;;;;;;;;"}
|
|
@@ -1,8 +1,303 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Capacitor
|
|
3
|
+
import Amplify
|
|
4
|
+
import AmplifyPlugins
|
|
5
|
+
import AWSPluginsCore
|
|
6
|
+
import AWSMobileClient
|
|
2
7
|
|
|
3
8
|
@objc public class AwsAmplify: NSObject {
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
9
|
+
private let TAG = "[Capacitor AwsAmplify]"
|
|
10
|
+
// static public let instance = AwsAmplify()
|
|
11
|
+
|
|
12
|
+
// private let sessionSubject = BehaviorSubject<Optional<AuthSession>>(value: nil)
|
|
13
|
+
// public var isLoggedIn$: Observable<Bool> {
|
|
14
|
+
// sessionSubject.map { session in
|
|
15
|
+
// session != nil
|
|
16
|
+
// }
|
|
17
|
+
// }
|
|
18
|
+
|
|
19
|
+
struct AccessTokenPayload: Decodable {
|
|
20
|
+
var device_key:String
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
override public init() {
|
|
24
|
+
super.init()
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
public func load(email: String,
|
|
28
|
+
password: String,
|
|
29
|
+
onSuccess: @escaping (AuthSignInResult) -> (),
|
|
30
|
+
onError: @escaping (any Error) -> ()) {
|
|
31
|
+
initAwsService()
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
func signIn(email: String,
|
|
35
|
+
password: String,
|
|
36
|
+
onSuccess: @escaping (AuthSignInResult) -> (),
|
|
37
|
+
onError: @escaping (any Error) -> ()) {
|
|
38
|
+
Amplify.Auth.signIn(username: email, password: password) { result in
|
|
39
|
+
do {
|
|
40
|
+
let signinResult: AuthSignInResult = try result.get()
|
|
41
|
+
print ("\(self.TAG) SignIn: " + (signinResult.isSignedIn ? "Sign in succeeded" : "Sign in not complete"))
|
|
42
|
+
onSuccess(signinResult)
|
|
43
|
+
} catch {
|
|
44
|
+
print ("\(self.TAG) Sign in failed \(error)")
|
|
45
|
+
onError(error)
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
public func federatedSignIn(
|
|
51
|
+
provider: String,
|
|
52
|
+
onSuccess: @escaping (AuthSignInResult) -> (),
|
|
53
|
+
onError: @escaping (any Error) -> ()
|
|
54
|
+
) {
|
|
55
|
+
var authProvider: AuthProvider
|
|
56
|
+
|
|
57
|
+
switch provider {
|
|
58
|
+
case "Google":
|
|
59
|
+
authProvider = AuthProvider.google
|
|
60
|
+
break
|
|
61
|
+
case "Facebook":
|
|
62
|
+
authProvider = AuthProvider.facebook
|
|
63
|
+
break
|
|
64
|
+
case "SignInWithApple":
|
|
65
|
+
authProvider = AuthProvider.apple
|
|
66
|
+
break
|
|
67
|
+
default:
|
|
68
|
+
authProvider = AuthProvider.google
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
print ("\(self.TAG) federatedSignIn \(authProvider)")
|
|
72
|
+
|
|
73
|
+
DispatchQueue.main.async {
|
|
74
|
+
Amplify.Auth.signInWithWebUI(for: authProvider, presentationAnchor: UIApplication.shared.windows.first!) { result in
|
|
75
|
+
switch result {
|
|
76
|
+
case .success(let result):
|
|
77
|
+
print("\(self.TAG) federatedSignIn effettuato con successo: \(result)")
|
|
78
|
+
onSuccess(result)
|
|
79
|
+
case .failure(let error):
|
|
80
|
+
print("\(self.TAG) Impossibile effettuare il federatedSignIn: \(error)")
|
|
81
|
+
onError(error)
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
public func signOut(
|
|
89
|
+
onSuccess: @escaping (Bool) -> (),
|
|
90
|
+
onError: @escaping (any Error) -> ()
|
|
91
|
+
) {
|
|
92
|
+
Amplify.Auth.signOut() { result in
|
|
93
|
+
switch result {
|
|
94
|
+
case .success:
|
|
95
|
+
onSuccess(true)
|
|
96
|
+
case .failure(let authError):
|
|
97
|
+
print("\(self.TAG) Sign out failed with error \(authError)")
|
|
98
|
+
onError(authError)
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
public func fetchAuthSession(
|
|
104
|
+
onSuccess: @escaping (JSObject) -> (),
|
|
105
|
+
onError: @escaping (any Error) -> ()
|
|
106
|
+
) {
|
|
107
|
+
Amplify.Auth.fetchAuthSession { result in
|
|
108
|
+
do {
|
|
109
|
+
let session = try result.get()
|
|
110
|
+
var ret: JSObject = [:]
|
|
111
|
+
|
|
112
|
+
// Get user sub or identity id
|
|
113
|
+
if let identityProvider = session as? AuthCognitoIdentityProvider {
|
|
114
|
+
let usersub = try identityProvider.getUserSub().get()
|
|
115
|
+
let identityId = try identityProvider.getIdentityId().get()
|
|
116
|
+
// print("User sub - \(usersub) and identity id \(identityId)")
|
|
117
|
+
|
|
118
|
+
ret["identityId"] = identityId
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
// Get AWS credentials
|
|
122
|
+
// if let awsCredentialsProvider = session as? AuthAWSCredentialsProvider {
|
|
123
|
+
// let credentials = try awsCredentialsProvider.getAWSCredentials().get()
|
|
124
|
+
// print("Access key - \(credentials.accessKey) ")
|
|
125
|
+
// }
|
|
126
|
+
|
|
127
|
+
// Get cognito user pool token
|
|
128
|
+
if let cognitoTokenProvider = session as? AuthCognitoTokensProvider {
|
|
129
|
+
let tokens = try cognitoTokenProvider.getCognitoTokens().get()
|
|
130
|
+
// print("Id token - \(tokens.idToken) ")
|
|
131
|
+
|
|
132
|
+
ret["accessToken"] = tokens.accessToken
|
|
133
|
+
ret["idToken"] = tokens.idToken
|
|
134
|
+
ret["refreshToken"] = tokens.refreshToken
|
|
135
|
+
|
|
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
|
+
// Retrieve the device key from the payload of access token
|
|
147
|
+
let accessToken = tokens.accessToken as NSString
|
|
148
|
+
// print("\(self.TAG) accessToken - \(tokens.idToken) ")
|
|
149
|
+
let chunks = accessToken.components(separatedBy: ".")
|
|
150
|
+
let accessTokenPayload = self.decodeJWTPart(part: chunks[1])
|
|
151
|
+
let deviceKey = accessTokenPayload?.device_key
|
|
152
|
+
|
|
153
|
+
ret["deviceKey"] = deviceKey
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
// self.sessionSubject.onNext(session)
|
|
157
|
+
|
|
158
|
+
print("\(self.TAG) - Fetch Auth Session successfully")
|
|
159
|
+
// print("\(self.TAG) - \(ret)")
|
|
160
|
+
onSuccess(ret)
|
|
161
|
+
} catch {
|
|
162
|
+
print("\(self.TAG) Fetch auth session failed with error - \(error)")
|
|
163
|
+
onError(error)
|
|
164
|
+
}
|
|
165
|
+
}
|
|
7
166
|
}
|
|
167
|
+
|
|
168
|
+
public func getCurrentUser() -> AuthUser {
|
|
169
|
+
return Amplify.Auth.getCurrentUser()!
|
|
170
|
+
}
|
|
171
|
+
|
|
172
|
+
func base64StringWithPadding(encodedString: String) -> String {
|
|
173
|
+
var stringTobeEncoded = encodedString.replacingOccurrences(of: "-", with: "+")
|
|
174
|
+
.replacingOccurrences(of: "_", with: "/")
|
|
175
|
+
let paddingCount = encodedString.count % 4
|
|
176
|
+
for _ in 0..<paddingCount {
|
|
177
|
+
stringTobeEncoded += "="
|
|
178
|
+
}
|
|
179
|
+
return stringTobeEncoded
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
func decodeJWTPart(part: String) -> AccessTokenPayload? {
|
|
183
|
+
let payloadPaddingString = base64StringWithPadding(encodedString: part)
|
|
184
|
+
guard let payloadData = Data(base64Encoded: payloadPaddingString) else {
|
|
185
|
+
fatalError("payload could not converted to data")
|
|
186
|
+
}
|
|
187
|
+
return try? JSONDecoder().decode(AccessTokenPayload.self, from: payloadData)
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
private func initAwsService() {
|
|
191
|
+
let auth: AuthCategoryConfiguration = AuthCategoryConfiguration.init(plugins: [
|
|
192
|
+
"awsCognitoAuthPlugin" : JSONValue.object([
|
|
193
|
+
"CredentialsProvider" : JSONValue.object([
|
|
194
|
+
"CognitoIdentity" : JSONValue.object([
|
|
195
|
+
"Default" : JSONValue.object([
|
|
196
|
+
"PoolId" : JSONValue.string("eu-central-1:a6bf0e4d-a6da-46e9-9002-8caef1e2f13a"),
|
|
197
|
+
"Region" : JSONValue.string("eu-central-1"),
|
|
198
|
+
])
|
|
199
|
+
])
|
|
200
|
+
]),
|
|
201
|
+
"CognitoUserPool" : JSONValue.object([
|
|
202
|
+
"Default" : JSONValue.object([
|
|
203
|
+
"PoolId" : JSONValue.string("eu-central-1_Khi2tppV3"),
|
|
204
|
+
"AppClientId" : JSONValue.string("2sidb0hc7h45en6iorg2p4idng"),
|
|
205
|
+
"Region" : JSONValue.string("eu-central-1"),
|
|
206
|
+
])
|
|
207
|
+
]),
|
|
208
|
+
"Auth" : JSONValue.object([
|
|
209
|
+
"Default" : JSONValue.object([
|
|
210
|
+
"authenticationFlowType" : JSONValue.string("USER_SRP_AUTH"),
|
|
211
|
+
"OAuth" : JSONValue.object([
|
|
212
|
+
"WebDomain" : JSONValue.string("fantaracing-apple.auth.eu-central-1.amazoncognito.com"),
|
|
213
|
+
"AppClientId" : JSONValue.string("2sidb0hc7h45en6iorg2p4idng"),
|
|
214
|
+
"SignInRedirectURI" : JSONValue.string("fantaracing-app://"),
|
|
215
|
+
"SignOutRedirectURI" : JSONValue.string("fantaracing-app://"),
|
|
216
|
+
"Scopes" : JSONValue.array([
|
|
217
|
+
JSONValue.string("phone"),
|
|
218
|
+
JSONValue.string("email"),
|
|
219
|
+
JSONValue.string("profile"),
|
|
220
|
+
JSONValue.string("openid"),
|
|
221
|
+
JSONValue.string("aws.cognito.signin.user.admin"),
|
|
222
|
+
])
|
|
223
|
+
]),
|
|
224
|
+
])
|
|
225
|
+
]),
|
|
226
|
+
])
|
|
227
|
+
])
|
|
228
|
+
|
|
229
|
+
let ampConfig: AmplifyConfiguration = AmplifyConfiguration.init(auth:auth)
|
|
230
|
+
do {
|
|
231
|
+
try Amplify.add(plugin: AWSCognitoAuthPlugin())
|
|
232
|
+
try Amplify.configure(ampConfig)
|
|
233
|
+
print("\(self.TAG) Amplify configured with auth plugin")
|
|
234
|
+
|
|
235
|
+
Amplify.Hub.listen(to: .auth) { payload in
|
|
236
|
+
|
|
237
|
+
switch payload.eventName {
|
|
238
|
+
case HubPayload.EventName.Auth.signedIn:
|
|
239
|
+
print("\(self.TAG) User signed in")
|
|
240
|
+
// Update UI
|
|
241
|
+
break
|
|
242
|
+
|
|
243
|
+
case HubPayload.EventName.Auth.sessionExpired:
|
|
244
|
+
print("\(self.TAG) Session expired")
|
|
245
|
+
// Re-authenticate the user
|
|
246
|
+
break
|
|
247
|
+
|
|
248
|
+
case HubPayload.EventName.Auth.signedOut:
|
|
249
|
+
// self.sessionSubject.onNext(nil)
|
|
250
|
+
print("\(self.TAG) User signed out")
|
|
251
|
+
// Update UI
|
|
252
|
+
break
|
|
253
|
+
|
|
254
|
+
case HubPayload.EventName.Auth.userDeleted:
|
|
255
|
+
print("\(self.TAG) User deleted")
|
|
256
|
+
// Update UI
|
|
257
|
+
break
|
|
258
|
+
|
|
259
|
+
case HubPayload.EventName.Auth.socialWebUISignInAPI:
|
|
260
|
+
print("\(self.TAG) Social login")
|
|
261
|
+
// self.fetchAuthSession { _ in } onError: { _ in }
|
|
262
|
+
|
|
263
|
+
break
|
|
264
|
+
|
|
265
|
+
default:
|
|
266
|
+
break
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
// print("\(self.TAG) Amplify.Hub.listen \(payload)")
|
|
270
|
+
}
|
|
271
|
+
} catch {
|
|
272
|
+
print("\(self.TAG) An error occurred setting up Amplify: \(error)")
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
// public func getSession() -> Optional<AuthSession> {
|
|
277
|
+
// do {
|
|
278
|
+
// return try self.sessionSubject.value()
|
|
279
|
+
// } catch {
|
|
280
|
+
// return nil
|
|
281
|
+
// }
|
|
282
|
+
// }
|
|
283
|
+
|
|
284
|
+
// public func hasFullRegistration() -> Observable<Bool> {
|
|
285
|
+
// return Observable.create { observer in
|
|
286
|
+
// AWSMobileClient.default().getUserAttributes { (userAttributes, error) in
|
|
287
|
+
// if error != nil {
|
|
288
|
+
// print("\(self.TAG) User attributes error: \(error)")
|
|
289
|
+
// observer.onNext(false)
|
|
290
|
+
// } else if let userAttributes = userAttributes {
|
|
291
|
+
// print("\(self.TAG) User attributes: \(userAttributes)")
|
|
292
|
+
// let registrationFull = userAttributes["custom:registration_full"]
|
|
293
|
+
// if registrationFull != nil {
|
|
294
|
+
// observer.onNext(true)
|
|
295
|
+
// } else {
|
|
296
|
+
// observer.onNext(false)
|
|
297
|
+
// }
|
|
298
|
+
// }
|
|
299
|
+
// }
|
|
300
|
+
// return Disposables.create()
|
|
301
|
+
// }
|
|
302
|
+
// }
|
|
8
303
|
}
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// Define the plugin using the CAP_PLUGIN Macro, and
|
|
5
5
|
// each method the plugin supports using the CAP_PLUGIN_METHOD macro.
|
|
6
6
|
CAP_PLUGIN(AwsAmplifyPlugin, "AwsAmplify",
|
|
7
|
+
CAP_PLUGIN_METHOD(load, CAPPluginReturnPromise);
|
|
7
8
|
CAP_PLUGIN_METHOD(signIn, CAPPluginReturnPromise);
|
|
8
9
|
CAP_PLUGIN_METHOD(signOut, CAPPluginReturnPromise);
|
|
9
10
|
CAP_PLUGIN_METHOD(federatedSignIn, CAPPluginReturnPromise);
|
|
@@ -9,15 +9,37 @@ import Capacitor
|
|
|
9
9
|
public class AwsAmplifyPlugin: CAPPlugin {
|
|
10
10
|
private let implementation = AwsAmplify()
|
|
11
11
|
|
|
12
|
+
@objc func load(_ call: CAPPluginCall) {
|
|
13
|
+
let email = call.getString("email") ?? ""
|
|
14
|
+
let password = call.getString("password") ?? ""
|
|
15
|
+
|
|
16
|
+
implementation.load(
|
|
17
|
+
email: email,
|
|
18
|
+
password: password,
|
|
19
|
+
onSuccess: {data in
|
|
20
|
+
self.implementation.fetchAuthSession(
|
|
21
|
+
onSuccess: {session in
|
|
22
|
+
call.resolve(session)
|
|
23
|
+
},
|
|
24
|
+
onError: {error in
|
|
25
|
+
call.reject(error.localizedDescription)
|
|
26
|
+
})
|
|
27
|
+
},
|
|
28
|
+
onError: {error in
|
|
29
|
+
print(error)
|
|
30
|
+
call.reject(error.localizedDescription)
|
|
31
|
+
})
|
|
32
|
+
}
|
|
33
|
+
|
|
12
34
|
@objc func signIn(_ call: CAPPluginCall) {
|
|
13
35
|
let email = call.getString("email") ?? ""
|
|
14
36
|
let password = call.getString("password") ?? ""
|
|
15
37
|
|
|
16
|
-
|
|
38
|
+
implementation.signIn(
|
|
17
39
|
email: email,
|
|
18
40
|
password: password,
|
|
19
41
|
onSuccess: {data in
|
|
20
|
-
self.
|
|
42
|
+
self.implementation.fetchAuthSession(
|
|
21
43
|
onSuccess: {session in
|
|
22
44
|
call.resolve(session)
|
|
23
45
|
},
|
|
@@ -32,7 +54,7 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
32
54
|
}
|
|
33
55
|
|
|
34
56
|
@objc func signOut(_ call: CAPPluginCall) {
|
|
35
|
-
self.
|
|
57
|
+
self.implementation.signOut(
|
|
36
58
|
onSuccess: { success in
|
|
37
59
|
call.resolve([
|
|
38
60
|
"logout": success
|
|
@@ -45,11 +67,11 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
45
67
|
@objc func federatedSignIn(_ call: CAPPluginCall) {
|
|
46
68
|
let provider = call.getString("provider") ?? ""
|
|
47
69
|
|
|
48
|
-
self.
|
|
70
|
+
self.implementation.federatedSignIn(
|
|
49
71
|
provider: provider,
|
|
50
72
|
onSuccess: { data in
|
|
51
73
|
print("federatedSignIn onSuccess \(data)")
|
|
52
|
-
self.
|
|
74
|
+
self.implementation.fetchAuthSession(
|
|
53
75
|
onSuccess: {session in
|
|
54
76
|
call.resolve(session)
|
|
55
77
|
},
|