@vardario/cognito-client 1.0.0 → 1.0.1

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.
@@ -134,7 +134,6 @@ export interface AuthenticationResult {
134
134
  AccessToken: string;
135
135
  ExpiresIn: number;
136
136
  IdToken: string;
137
- TokenType: string;
138
137
  RefreshToken: string;
139
138
  }
140
139
  export interface AuthenticationResponse {
@@ -150,6 +149,7 @@ export interface ChallengeResponse {
150
149
  USER_ID_FOR_SRP: string;
151
150
  };
152
151
  }
152
+ export declare function authResultToSession(authenticationResult: AuthenticationResult): Session;
153
153
  /**
154
154
  * Lightweight AWS Cogito client without any AWS SDK dependencies.
155
155
  */
@@ -161,7 +161,6 @@ export declare class CognitoClient {
161
161
  constructor({ userPoolId, userPoolClientId, endpoint, oAuth2: oAuth }: CognitoClientProps);
162
162
  static getDecodedTokenFromSession(session: Session): DecodedTokens;
163
163
  private cognitoRequest;
164
- private static authResultToSession;
165
164
  /**
166
165
  *
167
166
  * Performs user authentication with username and password through ALLOW_USER_SRP_AUTH .
@@ -33,6 +33,14 @@ export var CognitoIdentityProvider;
33
33
  CognitoIdentityProvider["Amazon"] = "LoginWithAmazon";
34
34
  CognitoIdentityProvider["Apple"] = "SignInWithApple";
35
35
  })(CognitoIdentityProvider || (CognitoIdentityProvider = {}));
36
+ export function authResultToSession(authenticationResult) {
37
+ return {
38
+ accessToken: authenticationResult.AccessToken,
39
+ idToken: authenticationResult.IdToken,
40
+ expiresIn: new Date().getTime() + authenticationResult.ExpiresIn * 1000,
41
+ refreshToken: authenticationResult.RefreshToken
42
+ };
43
+ }
36
44
  /**
37
45
  * Lightweight AWS Cogito client without any AWS SDK dependencies.
38
46
  */
@@ -68,14 +76,6 @@ export class CognitoClient {
68
76
  }
69
77
  return cognitoResponse.json();
70
78
  }
71
- static authResultToSession(authenticationResult) {
72
- return {
73
- accessToken: authenticationResult.AccessToken,
74
- idToken: authenticationResult.IdToken,
75
- expiresIn: new Date().getMilliseconds() / 1000 + authenticationResult.ExpiresIn,
76
- refreshToken: authenticationResult.RefreshToken
77
- };
78
- }
79
79
  /**
80
80
  *
81
81
  * Performs user authentication with username and password through ALLOW_USER_SRP_AUTH .
@@ -115,7 +115,7 @@ export class CognitoClient {
115
115
  ClientMetadata: {}
116
116
  };
117
117
  const { AuthenticationResult } = await this.cognitoRequest(respondToAuthChallengePayload, CognitoServiceTarget.RespondToAuthChallenge);
118
- return CognitoClient.authResultToSession(AuthenticationResult);
118
+ return authResultToSession(AuthenticationResult);
119
119
  }
120
120
  /**
121
121
  *
@@ -137,7 +137,7 @@ export class CognitoClient {
137
137
  ClientMetadata: {}
138
138
  };
139
139
  const { AuthenticationResult } = (await this.cognitoRequest(initiateAuthPayload, CognitoServiceTarget.InitiateAuth));
140
- const session = CognitoClient.authResultToSession(AuthenticationResult);
140
+ const session = authResultToSession(AuthenticationResult);
141
141
  return session;
142
142
  }
143
143
  /**
@@ -160,7 +160,7 @@ export class CognitoClient {
160
160
  if (!AuthenticationResult.RefreshToken) {
161
161
  AuthenticationResult.RefreshToken = refreshToken;
162
162
  }
163
- return CognitoClient.authResultToSession(AuthenticationResult);
163
+ return authResultToSession(AuthenticationResult);
164
164
  }
165
165
  /**
166
166
  *
@@ -352,16 +352,15 @@ export class CognitoClient {
352
352
  },
353
353
  body: urlParams.toString()
354
354
  });
355
- const { access_token, refresh_token, id_token, expires_in, token_type, error } = await response.json();
355
+ const { access_token, refresh_token, id_token, expires_in, error } = await response.json();
356
356
  if (error) {
357
357
  throw new Error(error);
358
358
  }
359
- const session = CognitoClient.authResultToSession({
359
+ const session = authResultToSession({
360
360
  AccessToken: access_token,
361
361
  RefreshToken: refresh_token,
362
362
  IdToken: id_token,
363
- ExpiresIn: expires_in,
364
- TokenType: token_type
363
+ ExpiresIn: expires_in
365
364
  });
366
365
  return session;
367
366
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@vardario/cognito-client",
3
- "version": "1.0.0",
3
+ "version": "1.0.1",
4
4
  "description": "",
5
5
  "license": "MIT",
6
6
  "author": "Sahin Vardar",