aws-amplify / amplify-js

A declarative JavaScript library for application development using cloud services.
https://docs.amplify.aws/lib/q/platform/js
Apache License 2.0
9.42k stars 2.12k forks source link

Allow Custom UserAgent for React Native #8304

Closed Jpoliachik closed 1 year ago

Jpoliachik commented 3 years ago

Is this related to a new or existing framework?

React Native

Is this related to a new or existing API?

Authentication

Is this related to another service?

Cognito

Describe the feature you'd like to request

Currently, the UserAgent header supplied in requests is static "aws-amplify/0.1.x react-native".

This is not a helpful UserAgent to sufficiently identify the device making the request. It is recommended to use a formula like:

application-name/1.6.4.176 CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3)

which could be generated by https://github.com/bebnev/react-native-user-agent at runtime.

But in order to use this, we need the ability to supply a custom UserAgent to the Amplify SDK.

Describe the solution you'd like

The user agent won't change at runtime, so its possible to supply this during Amplify configuration, eg:

    Amplify.configure({
      Auth: {
        ...authConfig,
        userAgent: "application-name/1.6.4.176 CFNetwork/897.15 Darwin/17.5.0 (iPhone/6s iOS/11.3)"
      },
      ...otherConfig
    });

Describe alternatives you've considered

I've tried hacking at the UserAgent variable to override but can't without forking the library.

See enhance-rn.js in the amazon-cognito-identity-js package: https://github.com/aws-amplify/amplify-js/blob/df95ea3724eb6406f64b03f25086cd3e8644cb5f/packages/amazon-cognito-identity-js/enhance-rn.js

import UserAgent from './src/UserAgent';
UserAgent.prototype.userAgent = 'aws-amplify/0.1.x react-native';

This value should be overrideable.

Additional context

No response

Is this something that you'd be interested in working on?

Jpoliachik commented 3 years ago

I have also tried:

import { appendToCognitoUserAgent } from "amazon-cognito-identity-js";
appendToCognitoUserAgent("my custom user agent");

prior to Auth.signIn(), but this seems to have no effect.

erinleigh90 commented 1 year ago

Hello! I wanted to let you know that we are no longer overriding the UserAgent for ReactNative customers.