Skip to content

Social Login with V2 - Can't retrieve authorizeUri from SP #190

@oshalygin

Description

@oshalygin

In recent development, I need to start leveraging the TOKEN_SET and TOKEN_REFRESH dispatched events so that I can properly pass them on subsequent API calls to the express application.

Looking at the documentation, those events are not dispatched in stormpath-react@1.3.X so I upgraded to stormpath-react@2.0.0.

After doing so, social login link throws the following error:

Uncaught TypeError: Cannot read property 'split' of undefined
    at SocialLoginLink._buildAuthorizationUri (eval at <anonymous> (bundle.js:4076), <anonymous>:11254:59)
    at eval (eval at <anonymous> (bundle.js:4076), <anonymous>:11315:42)
    at eval (eval at <anonymous> (bundle.js:4076), <anonymous>:938:12)
    at XMLHttpRequest.request.onreadystatechange (eval at <anonymous> (bundle.js:4076), <anonymous>:886:8)

Looking at the code, specifically this section:

_createClass(SocialLoginLink, [{
	    key: '_buildAuthorizationUri',
	    value: function _buildAuthorizationUri(accountStore, scope, redirectUri) {

	      // The authorizeUri includes the basic set of query parameters, but
	      // we need to be able to override them with values that the developer
	      // may supply via this library
              console.log(accountStore);
              console.log(scope);
              console.log(redirectUri);
	      var authorizationUri = accountStore.authorizeUri;

	      var authorizationUriBaseEndpoint = authorizationUri.split('?')[0]; //here

	      var defaultQueryString = authorizationUri.split('?')[1];

	      var provider = accountStore.provider;

	      var queryString = _utils2.default.parseQueryString(defaultQueryString);

	      return authorizationUriBaseEndpoint + '?' + _utils2.default.encodeQueryString((0, _xtend2.default)(queryString, {
	        client_id: provider.clientId,
	        scope: scope || provider.scope,
	        redirect_uri: redirectUri || _utils2.default.getCurrentHost(),
	        response_type: 'stormpath_token'
	      }));
	    }

From the above, console.log(accountStore) yields the following object:

Note I added special chars to the clientId here for security reasons but I can ping my exact clientId if necessary.

{
  href: "https://api.stormpath.com/v1/directories/5dOVvMXS9HuYWB9Gfq48Pb",
  name: "Local-ACME-Google"
  provider: {
    clientId: "4136362asdf855-6gsti0asdf6hk61bed5p211rm0lkofdki.apps.googleusercontent.com",
    href: "https://api.stormpath.com/v1/directories/5dOVvMXS9HuYWB9Gfq48Pb/provider",
    providerId: "google",
    scope: "email profile"
  }
}

Looking at the SP console, the AUTHORIZED REDIRECT URI is set appropriately,
image

It appears that the authorizeUri is not properly getting set in the accountStore

Looking further into userStore.getLoginViewData,

_context2.default.userStore.getLoginViewData(function (err, data) {
	        var fields = null;
	        var socialProviders = null;
          console.log(data);
	        if (err) {
	          fields = defaultFields;
	        } else if (data && data.form) {
	          fields = data.form.fields;
	          if (!_this2.props.hideSocial) {
	            data.accountStores.forEach(function (accountStore) {
                // More code here, but it's unrelated
}

The log of the data object from above:

{
      accountStores: [
         {
            href: "https://api.stormpath.com/v1/directories/5dOVvMXS9HuYWB9Gfq48Pb",
            name: "Local-ACME-Google",
            provider: {} // This is the same object as above, its populated with the clientId, href and providerId
         }
      ],
      form: {
         fields: Array[2] // this is populated with login/password objects
     }
}

This is somewhat related to #161 but in that case I wasn't setting the redirectUri appropriately in the SP Portal. This scenario seems quite a bit different.

Thanks as usual and glad to help if I can figure out why the redirectUri is not passed down.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions