Skip to content

Commit

Permalink
feat: pipe auth user agent details through to service call (#11755)
Browse files Browse the repository at this point in the history
* chore: copy Auth code to InternalAuth

* feat: add customUserAgentDetails param to InternalAuth methods

* feat: make AuthClass extend InternalAuthClass, override functions with extra param

* build: export auth internals from /internals scope

* fix: changes signUp back to method type instead of prop so Auth can extend the method

* chore: update auth lint settings to allow class arrow functions to end in semi-colon

* fix: add overloaded method signature back in - unrelated change

* test: fix auth tests by mocking InternalAuthClass instead of AuthClass

* chore: change arrow methods to normal functions

* fix: remove async from overridden async functions

* chore: increase bundle size limits

* chore: publish feature branch for testing

* chore: port code from CognitoUser and CognitoUserPool to internals

* chore: delete InternalCognitoUserPool - separate PR

* chore: update imports and class name

* feat: add userAgentValue param to cognito client api's

* feat: add userAgentValue param to InternalCognitoUser api's, pass to client

* feat: make CognitoUser extend InternalCognitoUser and override api's

* test: update tests to work with additional param, minor fix

* chore: clean up unused imports and const's

* feat: add missing userAgentValue param

* chore: add new param to documentation comments

* build: export InternalCognitoUser from internals scope

* fix: remove default from InternalCognitoUser to fix scoped export

* fix: fix typo causing signOut failure

* build: correct index.d.ts files with changes

* test: revert auth tests

* chore: increase bundle size limits

* chore: increase bundle size limits

* chore: port CognitoUserPool over to InternalCognitoUserPool

* chore: restore CognitoUserPool

* feat: add userAgentValue parameter to signUp

* feat: update class name and imports

* feat: make CognitoUserPool extend internal and override signUp

* feat: export InternalCognitoUserPool from internals index

* feat: send userAgentValue to client service call

* test: fix internalsIndex test

* build: export InternalCognitoUserPool from internals scope

* chore: update CognitoUserPool type to extend internal

* chore: increase bundle size limits

* feat: add utils for auth user agent

* feat: add/uncomment AuthActions

* feat: pass userAgentValue to OAuth

* feat: send user agent details through cognito

* test: update test to user InternalCognitoUserPool

* test: update test to user internal cognito classes

* fix: send user agent with auth details instead of received

* test: mock cognito internals in auth-attribute-test

* test: mock cognito internals in auth-federation-unit-tests

* test: mock cognito internals in auth-refresh-token-test

* test: mock cognito internals in hosted-ui.test

* test: mock cognito internals in totp-unit-test

* fix: add in missed user agent details

* fix: pass user agent details to private implementations

* fix: send user agent string instead of object

* fix: accidental replacement of currentUserPoolUser

* test: mock new private methods

* test: mock private method

* chore: send undefined instead of null for userAgentValue:

* test: account for added param in OAuth

* chore: increase bundle size limits

* chore: remove publishing of preid release

* chore: increase bundle size limit

* chore: remove comment

* fix: send undefined clientMetadata before useragentvalue

* fix: use InternalCognitoUser as underlying instance

* fix: send userAgentValue through fetchUser

* fix: send userAgentValue through _getUserData

* test: fix tests to expect userAgentValue

* fix: add missing param and AuthAction for currentCredentials

* chore: increase bundle size limits
  • Loading branch information
erinleigh90 committed Aug 14, 2023
1 parent 15e333c commit 9497c28
Show file tree
Hide file tree
Showing 26 changed files with 1,592 additions and 951 deletions.
47 changes: 24 additions & 23 deletions packages/amazon-cognito-identity-js/internals/index.d.ts

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -1378,7 +1378,7 @@ export class InternalCognitoUser {
const userData = this.getUserDataFromCache();

if (!userData) {
this.fetchUserData()
this.fetchUserData(userAgentValue)
.then(data => {
callback(null, data);
})
Expand All @@ -1387,7 +1387,7 @@ export class InternalCognitoUser {
}

if (this.isFetchUserDataAndTokenRequired(params)) {
this.fetchUserData()
this.fetchUserData(userAgentValue)
.then(data => {
return this.refreshSessionIfPossible(params, userAgentValue).then(
() => data
Expand Down Expand Up @@ -1436,10 +1436,10 @@ export class InternalCognitoUser {
* @param {string} userAgentValue Optional string containing custom user agent value
*/
fetchUserData(userAgentValue) {
return this.createGetUserRequest().then(data => {
return this.createGetUserRequest(userAgentValue).then(data => {
this.cacheUserData(data);
return data;
}, userAgentValue);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import Client from '../Client';
import CognitoUser from '../CognitoUser';
import { InternalCognitoUser } from '../internals';
import StorageHelper from '../StorageHelper';

const USER_POOL_ID_MAX_LENGTH = 55;
Expand Down Expand Up @@ -130,7 +131,7 @@ export class InternalCognitoUserPool {
};

const returnData = {
user: new CognitoUser(cognitoUser),
user: new InternalCognitoUser(cognitoUser),
userConfirmed: data.UserConfirmed,
userSub: data.UserSub,
codeDeliveryDetails: data.CodeDeliveryDetails,
Expand All @@ -156,7 +157,7 @@ export class InternalCognitoUserPool {
Storage: this.storage,
};

return new CognitoUser(cognitoUser);
return new InternalCognitoUser(cognitoUser);
}

return null;
Expand Down
4 changes: 2 additions & 2 deletions packages/analytics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,13 +66,13 @@
"name": "Analytics (Pinpoint)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Analytics, AWSPinpointProvider }",
"limit": "31.5 kB"
"limit": "31.57 kB"
},
{
"name": "Analytics (Kinesis)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Analytics, AWSKinesisProvider }",
"limit": "60.5 kB"
"limit": "60.82 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api-graphql/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
"name": "API (GraphQL client)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, GraphQLAPI }",
"limit": "89.52 kB"
"limit": "90.35 kB"
}
],
"jest": {
Expand Down
2 changes: 1 addition & 1 deletion packages/api/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"name": "API (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, API }",
"limit": "90.28 kB"
"limit": "91.12 kB"
}
],
"jest": {
Expand Down
14 changes: 9 additions & 5 deletions packages/auth/__tests__/auth-attribute-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ import {
CognitoAccessToken,
CognitoUserAttribute,
} from 'amazon-cognito-identity-js';
import {
InternalCognitoUserPool,
InternalCognitoUser,
} from 'amazon-cognito-identity-js/internals';

import { AuthOptions } from '../src/types';
import { InternalAuthClass } from '../src/internals/InternalAuth';
Expand All @@ -23,7 +27,7 @@ const authOptions: AuthOptions = {
describe('User-Attribute-validation', () => {
it('Check-non-verified-attributes', async () => {
const spyonAuthUserAttributes = jest
.spyOn(InternalAuthClass.prototype, 'userAttributes')
.spyOn(InternalAuthClass.prototype as any, '_userAttributes')
.mockImplementation((user: CognitoUser) => {
const emailAttribute = new CognitoUserAttribute({
Name: 'email',
Expand Down Expand Up @@ -75,10 +79,10 @@ describe('User-Attribute-validation', () => {
const auth = new Auth(authOptions);

const spyUserPoolCurrentUser = jest
.spyOn(CognitoUserPool.prototype, 'getCurrentUser')
.spyOn(InternalCognitoUserPool.prototype, 'getCurrentUser')
.mockImplementation(() => {
return new CognitoUser({
Pool: new CognitoUserPool({
Pool: new InternalCognitoUserPool({
UserPoolId: authOptions.userPoolId,
ClientId: authOptions.userPoolWebClientId,
}),
Expand All @@ -87,7 +91,7 @@ describe('User-Attribute-validation', () => {
});

const spyUserGetSession = jest
.spyOn(CognitoUser.prototype, 'getSession')
.spyOn(InternalCognitoUser.prototype, 'getSession')
.mockImplementation((callback: any) => {
const session = new CognitoUserSession({
AccessToken: new CognitoAccessToken({ AccessToken: 'accesstoken' }),
Expand All @@ -103,7 +107,7 @@ describe('User-Attribute-validation', () => {
});

const spyGetUserData = jest
.spyOn(CognitoUser.prototype, 'getUserData')
.spyOn(InternalCognitoUser.prototype, 'getUserData')
.mockImplementation(callback => {
const emailAttribute = {
Name: 'email',
Expand Down
12 changes: 8 additions & 4 deletions packages/auth/__tests__/auth-creds-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,15 @@ import { Credentials } from '@aws-amplify/core';
import { AuthOptions } from '../src/types';
import {
CognitoUser,
CognitoUserPool,
CognitoUserSession,
CognitoAccessToken,
CognitoIdToken,
CognitoUserPool,
} from 'amazon-cognito-identity-js';
import {
InternalCognitoUser,
InternalCognitoUserPool,
} from 'amazon-cognito-identity-js/internals';
const authOptions: AuthOptions = {
userPoolId: 'us-west-2_0xxxxxxxx',
userPoolWebClientId: 'awsUserPoolsWebClientId',
Expand All @@ -21,7 +25,7 @@ describe('credentials syncing tests', () => {
const auth = new Auth(authOptions);

jest
.spyOn(CognitoUser.prototype, 'authenticateUser')
.spyOn(InternalCognitoUser.prototype, 'authenticateUser')
.mockImplementation((authenticationDetails, callback) => {
const session = new CognitoUserSession({
AccessToken: new CognitoAccessToken({ AccessToken: 'accesstoken' }),
Expand All @@ -32,7 +36,7 @@ describe('credentials syncing tests', () => {
});

jest
.spyOn(CognitoUserPool.prototype, 'getCurrentUser')
.spyOn(InternalCognitoUserPool.prototype, 'getCurrentUser')
.mockImplementation(() => {
return new CognitoUser({
Pool: new CognitoUserPool({
Expand All @@ -49,7 +53,7 @@ describe('credentials syncing tests', () => {
});

jest
.spyOn(CognitoUser.prototype, 'getSession')
.spyOn(InternalCognitoUser.prototype, 'getSession')
.mockImplementation((callback: any) => {
callback(null, session);
});
Expand Down
Loading

0 comments on commit 9497c28

Please sign in to comment.