@falconeta/capacitor-aws-amplify 0.0.4 → 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 CHANGED
@@ -40,12 +40,12 @@ load(options: { cognitoConfig: AWSCognitoConfig; }) => Promise<void>
40
40
  ### signIn(...)
41
41
 
42
42
  ```typescript
43
- signIn(options: { email: string; password: string; identityId: string; }) => Promise<CognitoAuthSession>
43
+ signIn(options: { email: string; password: string; }) => Promise<CognitoAuthSession>
44
44
  ```
45
45
 
46
- | Param | Type |
47
- | ------------- | --------------------------------------------------------------------- |
48
- | **`options`** | <code>{ email: string; password: string; identityId: string; }</code> |
46
+ | Param | Type |
47
+ | ------------- | ------------------------------------------------- |
48
+ | **`options`** | <code>{ email: string; password: string; }</code> |
49
49
 
50
50
  **Returns:** <code>Promise&lt;<a href="#cognitoauthsession">CognitoAuthSession</a>&gt;</code>
51
51
 
@@ -55,12 +55,12 @@ signIn(options: { email: string; password: string; identityId: string; }) => Pro
55
55
  ### federatedSignIn(...)
56
56
 
57
57
  ```typescript
58
- federatedSignIn(options: { provider: string; identityId: string; }) => Promise<CognitoAuthSession>
58
+ federatedSignIn(options: { provider: string; }) => Promise<CognitoAuthSession>
59
59
  ```
60
60
 
61
- | Param | Type |
62
- | ------------- | ------------------------------------------------------ |
63
- | **`options`** | <code>{ provider: string; identityId: string; }</code> |
61
+ | Param | Type |
62
+ | ------------- | ---------------------------------- |
63
+ | **`options`** | <code>{ provider: string; }</code> |
64
64
 
65
65
  **Returns:** <code>Promise&lt;<a href="#cognitoauthsession">CognitoAuthSession</a>&gt;</code>
66
66
 
package/dist/docs.json CHANGED
@@ -25,12 +25,12 @@
25
25
  },
26
26
  {
27
27
  "name": "signIn",
28
- "signature": "(options: { email: string; password: string; identityId: string; }) => Promise<CognitoAuthSession>",
28
+ "signature": "(options: { email: string; password: string; }) => Promise<CognitoAuthSession>",
29
29
  "parameters": [
30
30
  {
31
31
  "name": "options",
32
32
  "docs": "",
33
- "type": "{ email: string; password: string; identityId: string; }"
33
+ "type": "{ email: string; password: string; }"
34
34
  }
35
35
  ],
36
36
  "returns": "Promise<CognitoAuthSession>",
@@ -43,12 +43,12 @@
43
43
  },
44
44
  {
45
45
  "name": "federatedSignIn",
46
- "signature": "(options: { provider: string; identityId: string; }) => Promise<CognitoAuthSession>",
46
+ "signature": "(options: { provider: string; }) => Promise<CognitoAuthSession>",
47
47
  "parameters": [
48
48
  {
49
49
  "name": "options",
50
50
  "docs": "",
51
- "type": "{ provider: string; identityId: string; }"
51
+ "type": "{ provider: string; }"
52
52
  }
53
53
  ],
54
54
  "returns": "Promise<CognitoAuthSession>",
@@ -5,11 +5,9 @@ export interface AwsAmplifyPlugin {
5
5
  signIn(options: {
6
6
  email: string;
7
7
  password: string;
8
- identityId: string;
9
8
  }): Promise<CognitoAuthSession>;
10
9
  federatedSignIn(options: {
11
10
  provider: string;
12
- identityId: string;
13
11
  }): Promise<CognitoAuthSession>;
14
12
  signOut(): Promise<any>;
15
13
  }
@@ -1 +1 @@
1
- {"version":3,"file":"definitions.js","sourceRoot":"","sources":["../../src/definitions.ts"],"names":[],"mappings":"","sourcesContent":["export interface AwsAmplifyPlugin {\n load(options: { cognitoConfig: AWSCognitoConfig }): Promise<void>;\n signIn(options: {\n email: string;\n password: string;\n 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"]}
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,17 +1,16 @@
1
1
  import { WebPlugin } from '@capacitor/core';
2
2
  import type { AWSCognitoConfig, AwsAmplifyPlugin, CognitoAuthSession } from './definitions';
3
3
  export declare class AwsAmplifyWeb extends WebPlugin implements AwsAmplifyPlugin {
4
+ private cognitoConfig?;
4
5
  load(options: {
5
6
  cognitoConfig: AWSCognitoConfig;
6
7
  }): Promise<void>;
7
8
  signIn(options: {
8
9
  email: string;
9
10
  password: string;
10
- identityId: string;
11
11
  }): Promise<CognitoAuthSession>;
12
12
  federatedSignIn(options: {
13
13
  provider: string;
14
- identityId: string;
15
14
  }): Promise<CognitoAuthSession>;
16
15
  signOut(): Promise<any>;
17
16
  private getCognitoAuthSession;
package/dist/esm/web.js CHANGED
@@ -2,26 +2,37 @@ import { WebPlugin } from '@capacitor/core';
2
2
  import { Amplify, Auth } from 'aws-amplify';
3
3
  export class AwsAmplifyWeb extends WebPlugin {
4
4
  async load(options) {
5
+ this.cognitoConfig = options.cognitoConfig;
5
6
  Amplify.configure(Object.assign({}, options.cognitoConfig));
6
7
  }
7
8
  async signIn(options) {
8
9
  // console.log(LOG_PREFIX, options);
10
+ if (!this.cognitoConfig) {
11
+ throw new Error('call load first');
12
+ }
9
13
  return new Promise((resolve, reject) => {
10
14
  Auth.signIn(options.email, options.password).then((user) => {
11
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
12
18
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
13
19
  });
14
20
  });
15
21
  }
16
22
  async federatedSignIn(options) {
17
23
  // console.log(LOG_PREFIX, options);
24
+ if (!this.cognitoConfig) {
25
+ throw new Error('call load first');
26
+ }
18
27
  return new Promise((resolve, reject) => {
19
28
  Auth.federatedSignIn(options)
20
29
  .then(_ => {
21
30
  // console.log(LOG_PREFIX + " credential", cred);
22
31
  Auth.currentAuthenticatedUser().then(user => {
23
32
  // console.log(LOG_PREFIX + " user", user);
24
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
25
36
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
26
37
  });
27
38
  })
@@ -1 +1 @@
1
- {"version":3,"file":"web.js","sourceRoot":"","sources":["../../src/web.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAE5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,aAAa,CAAC;AAQ5C,MAAM,OAAO,aAAc,SAAQ,SAAS;IAC1C,KAAK,CAAC,IAAI,CAAC,OAA4C;QACrD,OAAO,CAAC,SAAS,mBAAM,OAAO,CAAC,aAAa,EAAG,CAAC;IAClD,CAAC;IACD,KAAK,CAAC,MAAM,CAAC,OAIZ;QACC,oCAAoC;QACpC,OAAO,IAA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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"]}
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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AW,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 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"]}
@@ -11,26 +11,37 @@ const AwsAmplify = core.registerPlugin('AwsAmplify', {
11
11
 
12
12
  class AwsAmplifyWeb extends core.WebPlugin {
13
13
  async load(options) {
14
+ this.cognitoConfig = options.cognitoConfig;
14
15
  awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
15
16
  }
16
17
  async signIn(options) {
17
18
  // console.log(LOG_PREFIX, options);
19
+ if (!this.cognitoConfig) {
20
+ throw new Error('call load first');
21
+ }
18
22
  return new Promise((resolve, reject) => {
19
23
  awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
20
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
21
27
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
22
28
  });
23
29
  });
24
30
  }
25
31
  async federatedSignIn(options) {
26
32
  // console.log(LOG_PREFIX, options);
33
+ if (!this.cognitoConfig) {
34
+ throw new Error('call load first');
35
+ }
27
36
  return new Promise((resolve, reject) => {
28
37
  awsAmplify.Auth.federatedSignIn(options)
29
38
  .then(_ => {
30
39
  // console.log(LOG_PREFIX + " credential", cred);
31
40
  awsAmplify.Auth.currentAuthenticatedUser().then(user => {
32
41
  // console.log(LOG_PREFIX + " user", user);
33
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
34
45
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
35
46
  });
36
47
  })
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n 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,OAAO,CAAC,UAAU,CAAC,CAAC;AAChG,gBAAgB,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,EAAE,CAAC;AAC5E,aAAa,CAAC,CAAC;AACf,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;AACnC;AACA,QAAQ,OAAO,IAAI,OAAO,CAAC,CAAC,OAAO,EAA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1
+ {"version":3,"file":"plugin.cjs.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n this.cognitoConfig = options.cognitoConfig;\n Amplify.configure(Object.assign({}, options.cognitoConfig));\n }\n async signIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.signIn(options.email, options.password).then((user) => {\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n });\n }\n async federatedSignIn(options) {\n // console.log(LOG_PREFIX, options);\n if (!this.cognitoConfig) {\n throw new Error('call load first');\n }\n return new Promise((resolve, reject) => {\n Auth.federatedSignIn(options)\n .then(_ => {\n // console.log(LOG_PREFIX + \" credential\", cred);\n Auth.currentAuthenticatedUser().then(user => {\n // console.log(LOG_PREFIX + \" user\", user);\n const cognitoAuthSession = this.getCognitoAuthSession(user, \n // eslint-disable-next-line @typescript-eslint/no-non-null-assertion\n this.cognitoConfig.aws_cognito_identity_pool_id);\n cognitoAuthSession ? resolve(cognitoAuthSession) : reject();\n });\n })\n .catch(err => reject(err));\n });\n }\n async signOut() {\n return Auth.signOut();\n }\n getCognitoAuthSession(user, identityId) {\n const userSession = user.getSignInUserSession();\n if (userSession) {\n const res = {\n accessToken: userSession.getAccessToken().getJwtToken(),\n idToken: userSession.getIdToken().getJwtToken(),\n identityId: identityId,\n refreshToken: userSession.getRefreshToken().getToken(),\n deviceKey: userSession.getAccessToken().decodePayload().device_key,\n };\n return res;\n }\n return null;\n }\n}\n//# sourceMappingURL=web.js.map"],"names":["registerPlugin","WebPlugin","Amplify","Auth"],"mappings":";;;;;;;AACK,MAAC,UAAU,GAAGA,mBAAc,CAAC,YAAY,EAAE;AAChD,IAAI,GAAG,EAAE,MAAM,mDAAe,CAAC,IAAI,CAAC,CAAC,IAAI,IAAI,CAAC,CAAC,aAAa,EAAE,CAAC;AAC/D,CAAC;;ACDM,MAAM,aAAa,SAASC,cAAS,CAAC;AAC7C,IAAI,MAAM,IAAI,CAAC,OAAO,EAAE;AACxB,QAAQ,IAAI,CAAC,aAAa,GAAG,OAAO,CAAC,aAAa,CAAC;AACnD,QAAQC,kBAAO,CAAC,SAAS,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE,EAAE,OAAO,CAAC,aAAa,CAAC,CAAC,CAAC;AACpE,KAAK;AACL,IAAI,MAAM,MAAM,CAAC,OAAO,EAAE;AAC1B;AACA,QAAQ,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE;AACjC,YAAY,MAAM,IAAI,KAAK,CAAC,iBAAiB,CAAC,CAAC;AAC/C,SAAS;AACT,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;AAC1E;AACA,gBAAgB,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;AACjE,gBAAgB,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,EAAE,CAAC;AAC5E,aAAa,CAAC,CAAC;AACf,SAAS,CAAC,CAAC;AACX,KAAK;AACL,IAAI,MAAM,eAAe,CAAC,OAAO,EAAE;AACnC;AACA,QAA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AgB,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
@@ -7,26 +7,37 @@ var capacitorAwsAmplify = (function (exports, core, awsAmplify) {
7
7
 
8
8
  class AwsAmplifyWeb extends core.WebPlugin {
9
9
  async load(options) {
10
+ this.cognitoConfig = options.cognitoConfig;
10
11
  awsAmplify.Amplify.configure(Object.assign({}, options.cognitoConfig));
11
12
  }
12
13
  async signIn(options) {
13
14
  // console.log(LOG_PREFIX, options);
15
+ if (!this.cognitoConfig) {
16
+ throw new Error('call load first');
17
+ }
14
18
  return new Promise((resolve, reject) => {
15
19
  awsAmplify.Auth.signIn(options.email, options.password).then((user) => {
16
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
17
23
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
18
24
  });
19
25
  });
20
26
  }
21
27
  async federatedSignIn(options) {
22
28
  // console.log(LOG_PREFIX, options);
29
+ if (!this.cognitoConfig) {
30
+ throw new Error('call load first');
31
+ }
23
32
  return new Promise((resolve, reject) => {
24
33
  awsAmplify.Auth.federatedSignIn(options)
25
34
  .then(_ => {
26
35
  // console.log(LOG_PREFIX + " credential", cred);
27
36
  awsAmplify.Auth.currentAuthenticatedUser().then(user => {
28
37
  // console.log(LOG_PREFIX + " user", user);
29
- const cognitoAuthSession = this.getCognitoAuthSession(user, options.identityId);
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);
30
41
  cognitoAuthSession ? resolve(cognitoAuthSession) : reject();
31
42
  });
32
43
  })
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["esm/index.js","esm/web.js"],"sourcesContent":["import { registerPlugin } from '@capacitor/core';\nconst AwsAmplify = registerPlugin('AwsAmplify', {\n web: () => import('./web').then(m => new m.AwsAmplifyWeb()),\n});\nexport * from './definitions';\nexport { AwsAmplify };\n//# sourceMappingURL=index.js.map","import { WebPlugin } from '@capacitor/core';\nimport { Amplify, Auth } from 'aws-amplify';\nexport class AwsAmplifyWeb extends WebPlugin {\n async load(options) {\n 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;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AkB,CAAC,GAAG,MAAM,EAAE,CAAC;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
+ {"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,IAA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,IAAI;IAC7D;IACA,oBAAoB,MAAM,kBAAkB,GAAG,IAAI,CAAC,qBAAqB,CAAC,IAAI;IAC9E;IACA,oBAAoB,IAAI,CAAC,aAAa,CAAC,4BAA4B,CAAC,CAAC;IACrE,oBAAoB,kBAAkB,GAAG,OAAO,CAAC,kBAAkB,CAAC,GAAG,MAAM,EAAE,CAAC;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;;;;;;;;;;;;;;;;;"}
@@ -24,11 +24,10 @@ import AWSMobileClient
24
24
  super.init()
25
25
  }
26
26
 
27
- public func load(email: String,
28
- password: String,
29
- onSuccess: @escaping (AuthSignInResult) -> (),
27
+ public func load(cognitoConfig: JSObject,
28
+ onSuccess: @escaping () -> (),
30
29
  onError: @escaping (any Error) -> ()) {
31
- initAwsService()
30
+ initAwsService(cognitoConfig: cognitoConfig, onSuccess: onSuccess, onError: onError)
32
31
  }
33
32
 
34
33
  func signIn(email: String,
@@ -187,39 +186,50 @@ import AWSMobileClient
187
186
  return try? JSONDecoder().decode(AccessTokenPayload.self, from: payloadData)
188
187
  }
189
188
 
190
- 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
+
191
207
  let auth: AuthCategoryConfiguration = AuthCategoryConfiguration.init(plugins: [
192
208
  "awsCognitoAuthPlugin" : JSONValue.object([
193
209
  "CredentialsProvider" : JSONValue.object([
194
210
  "CognitoIdentity" : JSONValue.object([
195
211
  "Default" : JSONValue.object([
196
- "PoolId" : JSONValue.string("eu-central-1:a6bf0e4d-a6da-46e9-9002-8caef1e2f13a"),
197
- "Region" : JSONValue.string("eu-central-1"),
212
+ "PoolId" : JSONValue.string(poolId),
213
+ "Region" : JSONValue.string(region),
198
214
  ])
199
215
  ])
200
216
  ]),
201
217
  "CognitoUserPool" : JSONValue.object([
202
218
  "Default" : JSONValue.object([
203
- "PoolId" : JSONValue.string("eu-central-1_Khi2tppV3"),
204
- "AppClientId" : JSONValue.string("2sidb0hc7h45en6iorg2p4idng"),
205
- "Region" : JSONValue.string("eu-central-1"),
219
+ "PoolId" : JSONValue.string(userPoolId),
220
+ "AppClientId" : JSONValue.string(clientId),
221
+ "Region" : JSONValue.string(region),
206
222
  ])
207
223
  ]),
208
224
  "Auth" : JSONValue.object([
209
225
  "Default" : JSONValue.object([
210
226
  "authenticationFlowType" : JSONValue.string("USER_SRP_AUTH"),
211
227
  "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
- ])
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)
223
233
  ]),
224
234
  ])
225
235
  ]),
@@ -268,8 +278,10 @@ import AWSMobileClient
268
278
 
269
279
  // print("\(self.TAG) Amplify.Hub.listen \(payload)")
270
280
  }
281
+ onSuccess()
271
282
  } catch {
272
283
  print("\(self.TAG) An error occurred setting up Amplify: \(error)")
284
+ onError(error)
273
285
  }
274
286
  }
275
287
 
@@ -10,20 +10,12 @@ public class AwsAmplifyPlugin: CAPPlugin {
10
10
  private let implementation = AwsAmplify()
11
11
 
12
12
  @objc func load(_ call: CAPPluginCall) {
13
- let email = call.getString("email") ?? ""
14
- let password = call.getString("password") ?? ""
13
+ let cognitoConfig = call.getObject("cognitoConfig")!
15
14
 
16
15
  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
- })
16
+ cognitoConfig: cognitoConfig,
17
+ onSuccess: {
18
+ call.resolve()
27
19
  },
28
20
  onError: {error in
29
21
  print(error)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@falconeta/capacitor-aws-amplify",
3
- "version": "0.0.4",
3
+ "version": "0.0.5",
4
4
  "description": "plugin that handle amplify features",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",