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(auth): add a default deviceName when remembering device #13022

Merged
merged 6 commits into from May 2, 2024

Conversation

ashwinkumar6
Copy link
Contributor

@ashwinkumar6 ashwinkumar6 commented Feb 17, 2024

Description of changes

  • Add a default deviceName for web and RN when making a ConfirmDevice service call
  • The navigator.userAgent API causes a warning in Chrome DevTools (Issues tab) starting with version 92
    • Use navigator.userAgentData (when available) instead of navigator.userAgent

Note:
The navigator.userAgentData API involves introducing randomness by adding a string Not_A_Brand | Not_A Brand | Not A(Brand | ... to prevent user fingerprinting. The deviceName passed to the ConfirmDevice service API is called every time the user signs-in until the rememberDevice API is called, after which it just updates the status. It isn't a concern if the deviceName changes later on.

Device name output / platform

Verified the following devices names on cognito console
Screenshot 2024-02-17 at 6 56 15 AM

Issue #, if available

#12854

Description of how you validated changes

Tested the following flows

MFA: always; DeviceTracking: Opt-in
1. signIn -> confirmSignIn -> signOut
new entry added in "Device tracking log" (cognito console) table each time this is done with "Remembered" as NO

2. signIn -> confirmSignIn -> rememberDevice -> signOut
new entry added in "Device tracking log" table time with "Remembered" as YES. (calling rememberDevice
again has no affect)

3. signIn -> fetchdevices() ->  signOut
device is remembered, able to bypass MFA. 
deviceName is present in new `name` key

Verified fetchDevices returns

[
    {
        "id": "us-west-2...",
        "name": "macOS 14.3.1 arm macOS Not A(Brand/99.0.0.0;Google Chrome/121.0.6167.184;Chromium/121.0.6167.184",
        "attributes": {
            "device_status": "valid",
            "device_name": "macOS 14.3.1 arm macOS Not A(Brand/99.0.0.0;Google Chrome/121.0.6167.184;Chromium/121.0.6167.184",
            "last_ip_used": "240...."
        },
        "createDate": "2024-02-17T01:17:42.046Z",
        "lastModifiedDate": "2024-02-17T01:33:11.770Z",
        "lastAuthenticatedDate": "2024-02-17T01:17:42.000Z"
    }
]

Checklist

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@ashwinkumar6
Copy link
Contributor Author

ashwinkumar6 commented Feb 17, 2024

Blocked by #13015
Once the same is merged we can update the target of this PR

@ashwinkumar6 ashwinkumar6 changed the title feat(react-native): add getDeviceName util feat(auth): add a default deviceName when remembering device Feb 17, 2024
Copy link
Contributor

@kvramyasri7 kvramyasri7 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Great job!!!!!

@cwomack cwomack mentioned this pull request Apr 16, 2024
3 tasks
@ashwinkumar6 ashwinkumar6 changed the base branch from ashwin-rn-getDeviceName to main May 1, 2024 18:03
@ashwinkumar6 ashwinkumar6 marked this pull request as ready for review May 1, 2024 18:03
@ashwinkumar6 ashwinkumar6 requested review from a team as code owners May 1, 2024 18:03
* 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:109.0) Gecko/20100101 Firefox/115.0'
*/
export const getDeviceName = async (): Promise<string> => {
const { userAgentData } = navigator as NavigatorUA;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

userAgentData is experimental and hence isn't typed but is officially recommended by google.

The support for userAgentData is still limited and so we have a fall back to option to use userAgent

Since userAgentData is experimental can we just use userAgent across all browsers ?

No, using only userAgent would result in chrome triggering Audit usage of navigator.userAgent, navigator.appVersion, and navigator.platform and reopening an old issue.

@ashwinkumar6 ashwinkumar6 requested a review from a team as a code owner May 1, 2024 21:00
const attributes = DeviceAttributes.reduce(
(attrs: any, { Name, Value }) => {
if (Name && Value) {
if (Name === 'device_name') deviceName = Value;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is it needed to assert for this specific device name ?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The deviceName is returned by the service call in DeviceAttributes on the device_name attribute. We were doing the same in V5 as well

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not opposed to creating our own types, but I wonder if there's a pre-built @types package we could use if it's well-maintained?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Took a reference of the types from this package user-agent-data-types but since it was less widely used, added the types directly

@ashwinkumar6 ashwinkumar6 merged commit 5f34186 into aws-amplify:main May 2, 2024
30 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants