@falconeta/capacitor-aws-amplify 0.0.3 → 0.0.5
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 +34 -8
- package/dist/docs.json +73 -4
- package/dist/esm/definitions.d.ts +17 -2
- package/dist/esm/definitions.js.map +1 -1
- package/dist/esm/web.d.ts +5 -3
- package/dist/esm/web.js +17 -3
- package/dist/esm/web.js.map +1 -1
- package/dist/plugin.cjs.js +16 -2
- package/dist/plugin.cjs.js.map +1 -1
- package/dist/plugin.js +16 -2
- package/dist/plugin.js.map +1 -1
- package/ios/Plugin/AwsAmplify.swift +75 -20
- package/ios/Plugin/AwsAmplifyPlugin.m +1 -0
- package/ios/Plugin/AwsAmplifyPlugin.swift +19 -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,15 +24,28 @@ 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
|
|
29
|
-
signIn(options: { email: string; password: string;
|
|
43
|
+
signIn(options: { email: string; password: string; }) => Promise<CognitoAuthSession>
|
|
30
44
|
```
|
|
31
45
|
|
|
32
|
-
| Param | Type
|
|
33
|
-
| ------------- |
|
|
34
|
-
| **`options`** | <code>{ email: string; password: string;
|
|
46
|
+
| Param | Type |
|
|
47
|
+
| ------------- | ------------------------------------------------- |
|
|
48
|
+
| **`options`** | <code>{ email: string; password: string; }</code> |
|
|
35
49
|
|
|
36
50
|
**Returns:** <code>Promise<<a href="#cognitoauthsession">CognitoAuthSession</a>></code>
|
|
37
51
|
|
|
@@ -41,12 +55,12 @@ signIn(options: { email: string; password: string; identityId: string; }) => Pro
|
|
|
41
55
|
### federatedSignIn(...)
|
|
42
56
|
|
|
43
57
|
```typescript
|
|
44
|
-
federatedSignIn(options: { provider: string;
|
|
58
|
+
federatedSignIn(options: { provider: string; }) => Promise<CognitoAuthSession>
|
|
45
59
|
```
|
|
46
60
|
|
|
47
|
-
| Param | Type
|
|
48
|
-
| ------------- |
|
|
49
|
-
| **`options`** | <code>{ provider: string;
|
|
61
|
+
| Param | Type |
|
|
62
|
+
| ------------- | ---------------------------------- |
|
|
63
|
+
| **`options`** | <code>{ provider: string; }</code> |
|
|
50
64
|
|
|
51
65
|
**Returns:** <code>Promise<<a href="#cognitoauthsession">CognitoAuthSession</a>></code>
|
|
52
66
|
|
|
@@ -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,14 +5,32 @@
|
|
|
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
|
-
"signature": "(options: { email: string; password: string;
|
|
28
|
+
"signature": "(options: { email: string; password: string; }) => Promise<CognitoAuthSession>",
|
|
11
29
|
"parameters": [
|
|
12
30
|
{
|
|
13
31
|
"name": "options",
|
|
14
32
|
"docs": "",
|
|
15
|
-
"type": "{ email: string; password: string;
|
|
33
|
+
"type": "{ email: string; password: string; }"
|
|
16
34
|
}
|
|
17
35
|
],
|
|
18
36
|
"returns": "Promise<CognitoAuthSession>",
|
|
@@ -25,12 +43,12 @@
|
|
|
25
43
|
},
|
|
26
44
|
{
|
|
27
45
|
"name": "federatedSignIn",
|
|
28
|
-
"signature": "(options: { provider: string;
|
|
46
|
+
"signature": "(options: { provider: string; }) => Promise<CognitoAuthSession>",
|
|
29
47
|
"parameters": [
|
|
30
48
|
{
|
|
31
49
|
"name": "options",
|
|
32
50
|
"docs": "",
|
|
33
|
-
"type": "{ provider: string;
|
|
51
|
+
"type": "{ provider: string; }"
|
|
34
52
|
}
|
|
35
53
|
],
|
|
36
54
|
"returns": "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,12 +1,13 @@
|
|
|
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;
|
|
5
|
-
identityId: string;
|
|
6
8
|
}): Promise<CognitoAuthSession>;
|
|
7
9
|
federatedSignIn(options: {
|
|
8
10
|
provider: string;
|
|
9
|
-
identityId: string;
|
|
10
11
|
}): Promise<CognitoAuthSession>;
|
|
11
12
|
signOut(): Promise<any>;
|
|
12
13
|
}
|
|
@@ -17,3 +18,17 @@ export interface CognitoAuthSession {
|
|
|
17
18
|
refreshToken: string;
|
|
18
19
|
deviceKey: string | null;
|
|
19
20
|
}
|
|
21
|
+
export interface AWSCognitoConfig {
|
|
22
|
+
aws_cognito_region: string;
|
|
23
|
+
aws_user_pools_id: string;
|
|
24
|
+
aws_user_pools_web_client_id: string;
|
|
25
|
+
aws_cognito_identity_pool_id: string;
|
|
26
|
+
aws_mandatory_sign_in: string;
|
|
27
|
+
oauth: {
|
|
28
|
+
domain: string;
|
|
29
|
+
scope: string[];
|
|
30
|
+
redirectSignIn: string;
|
|
31
|
+
redirectSignOut: string;
|
|
32
|
+
responseType: 'code';
|
|
33
|
+
};
|
|
34
|
+
}
|
|
@@ -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
|
|
1
|
+
{"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession>;\n federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession>;\n signOut(): Promise<any>;\n}\n\nexport interface CognitoAuthSession {\n accessToken: string;\n idToken: string;\n identityId: string;\n refreshToken: string;\n deviceKey: string | null;\n}\n\nexport interface AWSCognitoConfig {\n aws_cognito_region: string;\n aws_user_pools_id: string;\n aws_user_pools_web_client_id: string;\n aws_cognito_identity_pool_id: string;\n aws_mandatory_sign_in: string;\n oauth: {\n domain: string;\n scope: string[];\n redirectSignIn: string;\n redirectSignOut: string;\n responseType: 'code';\n };\n}\n"]}
|
package/dist/esm/web.d.ts
CHANGED
|
@@ -1,14 +1,16 @@
|
|
|
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
|
+
private cognitoConfig?;
|
|
5
|
+
load(options: {
|
|
6
|
+
cognitoConfig: AWSCognitoConfig;
|
|
7
|
+
}): Promise<void>;
|
|
4
8
|
signIn(options: {
|
|
5
9
|
email: string;
|
|
6
10
|
password: string;
|
|
7
|
-
identityId: string;
|
|
8
11
|
}): Promise<CognitoAuthSession>;
|
|
9
12
|
federatedSignIn(options: {
|
|
10
13
|
provider: string;
|
|
11
|
-
identityId: string;
|
|
12
14
|
}): Promise<CognitoAuthSession>;
|
|
13
15
|
signOut(): Promise<any>;
|
|
14
16
|
private getCognitoAuthSession;
|
package/dist/esm/web.js
CHANGED
|
@@ -1,24 +1,38 @@
|
|
|
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
|
+
this.cognitoConfig = options.cognitoConfig;
|
|
6
|
+
Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
7
|
+
}
|
|
4
8
|
async signIn(options) {
|
|
5
9
|
// console.log(LOG_PREFIX, options);
|
|
10
|
+
if (!this.cognitoConfig) {
|
|
11
|
+
throw new Error('call load first');
|
|
12
|
+
}
|
|
6
13
|
return new Promise((resolve, reject) => {
|
|
7
14
|
Auth.signIn(options.email, options.password).then((user) => {
|
|
8
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
15
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
16
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
17
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
9
18
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
10
19
|
});
|
|
11
20
|
});
|
|
12
21
|
}
|
|
13
22
|
async federatedSignIn(options) {
|
|
14
23
|
// console.log(LOG_PREFIX, options);
|
|
24
|
+
if (!this.cognitoConfig) {
|
|
25
|
+
throw new Error('call load first');
|
|
26
|
+
}
|
|
15
27
|
return new Promise((resolve, reject) => {
|
|
16
28
|
Auth.federatedSignIn(options)
|
|
17
29
|
.then(_ => {
|
|
18
30
|
// console.log(LOG_PREFIX + " credential", cred);
|
|
19
31
|
Auth.currentAuthenticatedUser().then(user => {
|
|
20
32
|
// console.log(LOG_PREFIX + " user", user);
|
|
21
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
33
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
34
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
35
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
22
36
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
23
37
|
});
|
|
24
38
|
})
|
package/dist/esm/web.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQ5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAG1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;QAC3C,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAGZ;QACC,oCAAoC;QACpC,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;YACvB,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;SACpC;QACD,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAAE,MAAM,EAAE,EAAE;YACrC,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,KAAK,EAAE,OAAO,CAAC,QAAQ,CAAC,CAAC,IAAI,CAAC,CAAC,IAAiB,EAAE,EAAE;gBACtE,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CACnD,IAAI;gBACJ,oEAAoE;gBACpE,IAAI,CAAC,aAAc,CAAC,4BAA4B,CACjD,CAAC;gBACF,kBAAkB,CAAC,CAAC,CAAC,OAAO,CAAC,kBAAkB,CAAC,CAAC,CAAC,CAAC,MAAM,EAAE,CAAC;YAC9D,CAAC,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AAE,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 private cognitoConfig?: AWSCognitoConfig;\n\n async load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void> {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure({ ...options.cognitoConfig });\n }\n async signIn(options: {\n email: string;\n password: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user: CognitoUser) => {\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig!.aws_cognito_identity_pool_id,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n\n async federatedSignIn(options: {\n provider: string;\n }): Promise<CognitoAuthSession> {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options as FederatedSignInOptions)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(\n user,\n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig!.aws_cognito_identity_pool_id,\n );\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n\n async signOut(): Promise<any> {\n return Auth.signOut();\n }\n\n private getCognitoAuthSession(user: CognitoUser, identityId: string) {\n const userSession = user.getSignInUserSession();\n\n if (userSession) {\n const res: CognitoAuthSession = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n\n return null;\n }\n}\n"]}
|
package/dist/plugin.cjs.js
CHANGED
|
@@ -10,24 +10,38 @@ const AwsAmplify = core.registerPlugin('AwsAmplify', {
|
|
|
10
10
|
});
|
|
11
11
|
|
|
12
12
|
class AwsAmplifyWeb extends core.WebPlugin {
|
|
13
|
+
async load(options) {
|
|
14
|
+
this.cognitoConfig = options.cognitoConfig;
|
|
15
|
+
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
16
|
+
}
|
|
13
17
|
async signIn(options) {
|
|
14
18
|
// console.log(LOG_PREFIX, options);
|
|
19
|
+
if (!this.cognitoConfig) {
|
|
20
|
+
throw new Error('call load first');
|
|
21
|
+
}
|
|
15
22
|
return new Promise((resolve, reject) => {
|
|
16
23
|
awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
|
|
17
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
24
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
25
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
26
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
18
27
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
19
28
|
});
|
|
20
29
|
});
|
|
21
30
|
}
|
|
22
31
|
async federatedSignIn(options) {
|
|
23
32
|
// console.log(LOG_PREFIX, options);
|
|
33
|
+
if (!this.cognitoConfig) {
|
|
34
|
+
throw new Error('call load first');
|
|
35
|
+
}
|
|
24
36
|
return new Promise((resolve, reject) => {
|
|
25
37
|
awsAmplify.Auth.federatedSignIn(options)
|
|
26
38
|
.then(_ => {
|
|
27
39
|
// console.log(LOG_PREFIX + " credential", cred);
|
|
28
40
|
awsAmplify.Auth.currentAuthenticatedUser().then(user => {
|
|
29
41
|
// console.log(LOG_PREFIX + " user", user);
|
|
30
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
42
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
43
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
44
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
31
45
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
32
46
|
});
|
|
33
47
|
})
|
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,
|
|
1
|
+
{"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IA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 var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
|
|
|
6
6
|
});
|
|
7
7
|
|
|
8
8
|
class AwsAmplifyWeb extends core.WebPlugin {
|
|
9
|
+
async load(options) {
|
|
10
|
+
this.cognitoConfig = options.cognitoConfig;
|
|
11
|
+
awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
|
|
12
|
+
}
|
|
9
13
|
async signIn(options) {
|
|
10
14
|
// console.log(LOG_PREFIX, options);
|
|
15
|
+
if (!this.cognitoConfig) {
|
|
16
|
+
throw new Error('call load first');
|
|
17
|
+
}
|
|
11
18
|
return new Promise((resolve, reject) => {
|
|
12
19
|
awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
|
|
13
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
20
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
21
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
22
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
14
23
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
15
24
|
});
|
|
16
25
|
});
|
|
17
26
|
}
|
|
18
27
|
async federatedSignIn(options) {
|
|
19
28
|
// console.log(LOG_PREFIX, options);
|
|
29
|
+
if (!this.cognitoConfig) {
|
|
30
|
+
throw new Error('call load first');
|
|
31
|
+
}
|
|
20
32
|
return new Promise((resolve, reject) => {
|
|
21
33
|
awsAmplify.Auth.federatedSignIn(options)
|
|
22
34
|
.then(_ => {
|
|
23
35
|
// console.log(LOG_PREFIX + " credential", cred);
|
|
24
36
|
awsAmplify.Auth.currentAuthenticatedUser().then(user => {
|
|
25
37
|
// console.log(LOG_PREFIX + " user", user);
|
|
26
|
-
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
38
|
+
const cognitoAuthSession = this.getCognitoAuthSession(user,
|
|
39
|
+
// eslint-disable-next-line @typescript-eslint/no-non-null-assertion
|
|
40
|
+
this.cognitoConfig.aws_cognito_identity_pool_id);
|
|
27
41
|
cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
|
|
28
42
|
});
|
|
29
43
|
})
|
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,
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;AACK,UAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;IAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;IAC/D,CAAC;;ICDM,MAAM,aAAa,SAASC,cAAS,CAAC;IAC7C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;IACxB,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;IACnD,QAAQC,kBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;IACpE,KAAK;IACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;IAC1B;IACA,QAAQ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;IACjC,YAAY,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,C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AC;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,4 +1,5 @@
|
|
|
1
1
|
import Foundation
|
|
2
|
+
import Capacitor
|
|
2
3
|
import Amplify
|
|
3
4
|
import AmplifyPlugins
|
|
4
5
|
import AWSPluginsCore
|
|
@@ -6,14 +7,14 @@ import AWSMobileClient
|
|
|
6
7
|
|
|
7
8
|
@objc public class AwsAmplify: NSObject {
|
|
8
9
|
private let TAG = "[Capacitor AwsAmplify]"
|
|
9
|
-
static public let instance =
|
|
10
|
+
// static public let instance = AwsAmplify()
|
|
10
11
|
|
|
11
|
-
private let sessionSubject = BehaviorSubject<Optional<AuthSession>>(value: nil)
|
|
12
|
-
public var isLoggedIn$: Observable<Bool> {
|
|
13
|
-
sessionSubject.map { session in
|
|
14
|
-
session != nil
|
|
15
|
-
}
|
|
16
|
-
}
|
|
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
|
+
// }
|
|
17
18
|
|
|
18
19
|
struct AccessTokenPayload: Decodable {
|
|
19
20
|
var device_key:String
|
|
@@ -23,8 +24,10 @@ import AWSMobileClient
|
|
|
23
24
|
super.init()
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
public func load(
|
|
27
|
-
|
|
27
|
+
public func load(cognitoConfig: JSObject,
|
|
28
|
+
onSuccess: @escaping () -> (),
|
|
29
|
+
onError: @escaping (any Error) -> ()) {
|
|
30
|
+
initAwsService(cognitoConfig: cognitoConfig, onSuccess: onSuccess, onError: onError)
|
|
28
31
|
}
|
|
29
32
|
|
|
30
33
|
func signIn(email: String,
|
|
@@ -149,7 +152,7 @@ import AWSMobileClient
|
|
|
149
152
|
ret["deviceKey"] = deviceKey
|
|
150
153
|
}
|
|
151
154
|
|
|
152
|
-
self.sessionSubject.onNext(session)
|
|
155
|
+
// self.sessionSubject.onNext(session)
|
|
153
156
|
|
|
154
157
|
print("\(self.TAG) - Fetch Auth Session successfully")
|
|
155
158
|
// print("\(self.TAG) - \(ret)")
|
|
@@ -183,10 +186,60 @@ import AWSMobileClient
|
|
|
183
186
|
return try? JSONDecoder().decode(AccessTokenPayload.self, from: payloadData)
|
|
184
187
|
}
|
|
185
188
|
|
|
186
|
-
private func initAwsService(
|
|
189
|
+
private func initAwsService(cognitoConfig: JSObject,
|
|
190
|
+
onSuccess: @escaping () -> (),
|
|
191
|
+
onError: @escaping (any Error) -> ()) {
|
|
192
|
+
let poolId = cognitoConfig["aws_cognito_identity_pool_id"] as! String
|
|
193
|
+
let region = cognitoConfig["aws_cognito_region"] as! String
|
|
194
|
+
let userPoolId = cognitoConfig["aws_user_pools_id"] as! String
|
|
195
|
+
let clientId = cognitoConfig["aws_user_pools_web_client_id"] as! String
|
|
196
|
+
|
|
197
|
+
let oauth = cognitoConfig["oauth"] as! JSObject
|
|
198
|
+
let domain = oauth["domain"] as! String
|
|
199
|
+
let redirectSignIn = oauth["redirectSignIn"] as! String
|
|
200
|
+
let redirectSignOut = oauth["redirectSignOut"] as! String
|
|
201
|
+
let scope = oauth["scope"] as! JSArray
|
|
202
|
+
|
|
203
|
+
let scopeConv = scope.map { value in
|
|
204
|
+
JSONValue.string(value as! String)
|
|
205
|
+
} as! [JSONValue]
|
|
206
|
+
|
|
207
|
+
let auth: AuthCategoryConfiguration = AuthCategoryConfiguration.init(plugins: [
|
|
208
|
+
"awsCognitoAuthPlugin" : JSONValue.object([
|
|
209
|
+
"CredentialsProvider" : JSONValue.object([
|
|
210
|
+
"CognitoIdentity" : JSONValue.object([
|
|
211
|
+
"Default" : JSONValue.object([
|
|
212
|
+
"PoolId" : JSONValue.string(poolId),
|
|
213
|
+
"Region" : JSONValue.string(region),
|
|
214
|
+
])
|
|
215
|
+
])
|
|
216
|
+
]),
|
|
217
|
+
"CognitoUserPool" : JSONValue.object([
|
|
218
|
+
"Default" : JSONValue.object([
|
|
219
|
+
"PoolId" : JSONValue.string(userPoolId),
|
|
220
|
+
"AppClientId" : JSONValue.string(clientId),
|
|
221
|
+
"Region" : JSONValue.string(region),
|
|
222
|
+
])
|
|
223
|
+
]),
|
|
224
|
+
"Auth" : JSONValue.object([
|
|
225
|
+
"Default" : JSONValue.object([
|
|
226
|
+
"authenticationFlowType" : JSONValue.string("USER_SRP_AUTH"),
|
|
227
|
+
"OAuth" : JSONValue.object([
|
|
228
|
+
"WebDomain" : JSONValue.string(domain),
|
|
229
|
+
"AppClientId" : JSONValue.string(clientId),
|
|
230
|
+
"SignInRedirectURI" : JSONValue.string(redirectSignIn),
|
|
231
|
+
"SignOutRedirectURI" : JSONValue.string(redirectSignOut),
|
|
232
|
+
"Scopes" : JSONValue.array(scopeConv)
|
|
233
|
+
]),
|
|
234
|
+
])
|
|
235
|
+
]),
|
|
236
|
+
])
|
|
237
|
+
])
|
|
238
|
+
|
|
239
|
+
let ampConfig: AmplifyConfiguration = AmplifyConfiguration.init(auth:auth)
|
|
187
240
|
do {
|
|
188
241
|
try Amplify.add(plugin: AWSCognitoAuthPlugin())
|
|
189
|
-
try Amplify.configure()
|
|
242
|
+
try Amplify.configure(ampConfig)
|
|
190
243
|
print("\(self.TAG) Amplify configured with auth plugin")
|
|
191
244
|
|
|
192
245
|
Amplify.Hub.listen(to: .auth) { payload in
|
|
@@ -203,7 +256,7 @@ import AWSMobileClient
|
|
|
203
256
|
break
|
|
204
257
|
|
|
205
258
|
case HubPayload.EventName.Auth.signedOut:
|
|
206
|
-
self.sessionSubject.onNext(nil)
|
|
259
|
+
// self.sessionSubject.onNext(nil)
|
|
207
260
|
print("\(self.TAG) User signed out")
|
|
208
261
|
// Update UI
|
|
209
262
|
break
|
|
@@ -225,18 +278,20 @@ import AWSMobileClient
|
|
|
225
278
|
|
|
226
279
|
// print("\(self.TAG) Amplify.Hub.listen \(payload)")
|
|
227
280
|
}
|
|
281
|
+
onSuccess()
|
|
228
282
|
} catch {
|
|
229
283
|
print("\(self.TAG) An error occurred setting up Amplify: \(error)")
|
|
284
|
+
onError(error)
|
|
230
285
|
}
|
|
231
286
|
}
|
|
232
287
|
|
|
233
|
-
public func getSession() -> Optional<AuthSession> {
|
|
234
|
-
do {
|
|
235
|
-
return try self.sessionSubject.value()
|
|
236
|
-
} catch {
|
|
237
|
-
return nil
|
|
238
|
-
}
|
|
239
|
-
}
|
|
288
|
+
// public func getSession() -> Optional<AuthSession> {
|
|
289
|
+
// do {
|
|
290
|
+
// return try self.sessionSubject.value()
|
|
291
|
+
// } catch {
|
|
292
|
+
// return nil
|
|
293
|
+
// }
|
|
294
|
+
// }
|
|
240
295
|
|
|
241
296
|
// public func hasFullRegistration() -> Observable<Bool> {
|
|
242
297
|
// return Observable.create { observer in
|
|
@@ -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,29 @@ import Capacitor
|
|
|
9
9
|
public class AwsAmplifyPlugin: CAPPlugin {
|
|
10
10
|
private let implementation = AwsAmplify()
|
|
11
11
|
|
|
12
|
+
@objc func load(_ call: CAPPluginCall) {
|
|
13
|
+
let cognitoConfig = call.getObject("cognitoConfig")!
|
|
14
|
+
|
|
15
|
+
implementation.load(
|
|
16
|
+
cognitoConfig: cognitoConfig,
|
|
17
|
+
onSuccess: {
|
|
18
|
+
call.resolve()
|
|
19
|
+
},
|
|
20
|
+
onError: {error in
|
|
21
|
+
print(error)
|
|
22
|
+
call.reject(error.localizedDescription)
|
|
23
|
+
})
|
|
24
|
+
}
|
|
25
|
+
|
|
12
26
|
@objc func signIn(_ call: CAPPluginCall) {
|
|
13
27
|
let email = call.getString("email") ?? ""
|
|
14
28
|
let password = call.getString("password") ?? ""
|
|
15
29
|
|
|
16
|
-
|
|
30
|
+
implementation.signIn(
|
|
17
31
|
email: email,
|
|
18
32
|
password: password,
|
|
19
33
|
onSuccess: {data in
|
|
20
|
-
self.
|
|
34
|
+
self.implementation.fetchAuthSession(
|
|
21
35
|
onSuccess: {session in
|
|
22
36
|
call.resolve(session)
|
|
23
37
|
},
|
|
@@ -32,7 +46,7 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
32
46
|
}
|
|
33
47
|
|
|
34
48
|
@objc func signOut(_ call: CAPPluginCall) {
|
|
35
|
-
self.
|
|
49
|
+
self.implementation.signOut(
|
|
36
50
|
onSuccess: { success in
|
|
37
51
|
call.resolve([
|
|
38
52
|
"logout": success
|
|
@@ -45,11 +59,11 @@ public class AwsAmplifyPlugin: CAPPlugin {
|
|
|
45
59
|
@objc func federatedSignIn(_ call: CAPPluginCall) {
|
|
46
60
|
let provider = call.getString("provider") ?? ""
|
|
47
61
|
|
|
48
|
-
self.
|
|
62
|
+
self.implementation.federatedSignIn(
|
|
49
63
|
provider: provider,
|
|
50
64
|
onSuccess: { data in
|
|
51
65
|
print("federatedSignIn onSuccess \(data)")
|
|
52
|
-
self.
|
|
66
|
+
self.implementation.fetchAuthSession(
|
|
53
67
|
onSuccess: {session in
|
|
54
68
|
call.resolve(session)
|
|
55
69
|
},
|