Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/user agent enhancements/auth oauth #11459

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
cb3a1a5
feat: add action and category to cognito calls based on Client reques…
erinleigh90 Jun 1, 2023
0a04806
fix: add exports to index.d.ts
erinleigh90 Jun 1, 2023
928067a
fix: fix silly mistakes in user agent work
erinleigh90 Jun 1, 2023
75ee645
test: fix spacing issue in index.test.js
erinleigh90 Jun 1, 2023
078177e
test: fix failing tests and update getAmplifyUserAgentString signatur…
erinleigh90 Jun 1, 2023
f101232
test: adds user agent test to CognitoUserPool
erinleigh90 Jun 1, 2023
3cf1df8
fix: update name missmatch
erinleigh90 Jun 1, 2023
031903f
fix: update name missmatch
erinleigh90 Jun 1, 2023
a439984
chore: add revokeToken for non global sign outs
erinleigh90 Jun 1, 2023
a947e70
test: fix name mismatch
erinleigh90 Jun 1, 2023
4a78d3b
test: fix test side effects:
erinleigh90 Jun 1, 2023
8894c84
test: add tests for InitiateAuth user agent headers
erinleigh90 Jun 1, 2023
3ede8e5
test: fix plain username password test
erinleigh90 Jun 1, 2023
3b08296
chore: set category/framework on UserAgent instead of UserAgent.proto…
erinleigh90 Jun 1, 2023
50e8272
test: user agent test for authaction confirmdevice
erinleigh90 Jun 1, 2023
d90f9c8
test: remove unnecessary spies
erinleigh90 Jun 1, 2023
6680876
test: fix test name
erinleigh90 Jun 1, 2023
6200183
test: add getDeviceResponse test for user agent header
erinleigh90 Jun 2, 2023
a2532c8
feat: add oauth action to token exchange
erinleigh90 Jun 3, 2023
b86c86b
Merge remote-tracking branch 'upstream/feat/user-agent-enhancements/m…
erinleigh90 Jun 3, 2023
647a819
Merge branch 'feat/user-agent-enhancements/auth' into feat/user-agent…
erinleigh90 Jun 3, 2023
44360ef
fix: get user agent and action from core in oauth
erinleigh90 Jun 3, 2023
1825b71
Change the action number for OAuthToken so as not to conflict with co…
erinleigh90 Jun 3, 2023
3822db3
Merge remote-tracking branch 'upstream/feat/user-agent-enhancements/m…
erinleigh90 Jun 5, 2023
04eba44
test: add missing props to core mock
erinleigh90 Jun 5, 2023
f7c4691
chore: adds comment pointing to standard auth actions
erinleigh90 Jun 5, 2023
49c1e8b
chore: increase auth bundle size limit
erinleigh90 Jun 5, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ export const Framework = {
export const authCategory = 'auth';

// Actions
/* TODO: Replace 'None' with all expected Actions */
export const AuthAction = {
SignUp: '1',
InitiateAuth: '2',
Expand Down
3 changes: 3 additions & 0 deletions packages/auth/__tests__/oauth-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ jest.mock('@aws-amplify/core', () => ({
dispatch: jest.fn(),
},
urlSafeEncode: jest.fn(),
Category: { Auth: 'auth' },
AuthAction: { OAuthToken: '25' },
getAmplifyUserAgentString: () => jest.fn(),
}));

function fetchMockReturn(response) {
Expand Down
2 changes: 1 addition & 1 deletion packages/auth/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@
"name": "Auth (top-level class)",
"path": "./lib-esm/index.js",
"import": "{ Amplify, Auth }",
"limit": "74 kB"
"limit": "74.1 kB"
}
],
"jest": {
Expand Down
20 changes: 19 additions & 1 deletion packages/auth/src/OAuth/OAuth.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,19 @@ import {
CognitoHostedUIIdentityProvider,
} from '../types/Auth';

import { ConsoleLogger as Logger, Hub, urlSafeEncode } from '@aws-amplify/core';
import {
AuthAction,
Category,
ConsoleLogger as Logger,
CustomUserAgentDetails,
getAmplifyUserAgentString,
Hub,
urlSafeEncode,
USER_AGENT_HEADER,
} from '@aws-amplify/core';

import { Sha256 } from '@aws-crypto/sha256-js';

const AMPLIFY_SYMBOL = (
typeof Symbol !== 'undefined' && typeof Symbol.for === 'function'
? Symbol.for('amplify_default')
Expand Down Expand Up @@ -159,11 +169,19 @@ export default class OAuth {
.map(([k, v]) => `${encodeURIComponent(k)}=${encodeURIComponent(v)}`)
.join('&');

const customUserAgentDetails: CustomUserAgentDetails = {
category: Category.Auth,
action: AuthAction.OAuthToken,
};

const { access_token, refresh_token, id_token, error } = await (
(await fetch(oAuthTokenEndpoint, {
method: 'POST',
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
[USER_AGENT_HEADER]: getAmplifyUserAgentString(
customUserAgentDetails
),
},
body,
})) as any
Expand Down
3 changes: 2 additions & 1 deletion packages/core/src/Platform/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,8 @@ export enum ApiAction {
GraphQl = '1',
}
export enum AuthAction {
None = '0',
// Standard Auth Actions currently defined in amazon-cognito-identity-js/Platform/constants.js
OAuthToken = '25',
}
export enum DataStoreAction {
Subscribe = '1',
Expand Down