sahat / satellizer

Token-based AngularJS Authentication
https://satellizer-sahat.rhcloud.com
MIT License
7.85k stars 1.13k forks source link

oauth2 is only returning code as response, passed userData is not present #716

Open saqueib opened 8 years ago

saqueib commented 8 years ago

@sahat thanks for great library, I have used it in many apps.

I am facing a problem where FitBit OAuth2 is not giving back my userData object value, here is the configuration object.

       $authProvider.oauth2({
          name: 'fitbit',
          url: 'http://localhost:3999?fitbit=1',
          clientId: 'xxxx',
          requiredUrlParams: ['display', 'scope'],
          scopeDelimiter: ' ',
          scope : ['activity', 'nutrition', 'heartrate', 'location'],
          redirectUri: 'http://domain.com/api/v1/service-connected/4',
          authorizationEndpoint: 'https://www.fitbit.com/oauth2/authorize',
        });

and in my controller I am doing

       $auth.authenticate('fitbit', { userId : 12})
         .then(function(res) {
          console.log( "success", res);
        })
        .catch(function(res) {
          console.log( "error", res);
       });

I need to send userId to server so I can link the account with user. I have many providers to add.

I also wanted to know is it possible to change OAuth2 configuration value from controller like

.controller('authCtrl', function($scope, $auth) {
     $authProvider.oauth2({
          name: 'fitbit',
          redirectUri: 'http://domain.com/api/v1/service-connected/4', 
              ...
              // dynamically set these properties since i have 15 custom providers 
});
sahat commented 8 years ago

I also wanted to know is it possible to change OAuth2 configuration value from controller like.

Not possible. In Angular, you must configure a provider before application starts, e.g. in app.config() block.

I need to send userId to server so I can link the account with user. I have many providers to add.

Double check your code. It works here.

screenshot 2016-01-20 00 52 39 screenshot 2016-01-20 00 52 50 screenshot 2016-01-20 00 52 59
saqueib commented 8 years ago

@sahat Thanks for quick reply, I have tested and its strange that its working with Facebook, but on Fitbit I am not getting the userId only code was returned.

sahat commented 8 years ago

Could you open local satellizer.js file and add console.log(data) over here: https://github.com/sahat/satellizer/blob/master/satellizer.js#L545 and here, right before sending it to the server: https://github.com/sahat/satellizer/blob/master/satellizer.js#L567

Are you seeing your custom userId value there?

saqueib commented 8 years ago

here is what I have tried, I have added console.log(data) on line 545 & 567. now I have changed the configuration and callback url on Fitbit api panel to http://localhost:3999 to see the response.

  1. on click connection button, popup opens and I fill the username & password.
  2. Fitbit redirects me to http://localhost:3999 and I see "code" => "9f6acd791c1d062fa4adbaf24a27dc886aa303c0"
  3. got nothing in console, not even undefined
Gillardo commented 8 years ago

I have had to dynamically change the clientId on my providers, as it is loaded from our web api. I have managed to do this using the following

Configure the $authProvider as normal:

home = angular.module('home', [ 'satellizer' ]).config ($authProvider) ->

$authProvider.github
clientId: '[redacted]'
scope: [ 'user:email' ]

return

Inject the SatellizerConfig object:

home.controller("HomeController", [ '$scope', 'SatellizerConfig'
($scope, SatellizerConfig) ->

And then modify it wherever you need to:

SatellizerConfig.providers['github'].scope = [ 'repo', 'user:email', 'write:repo_hook', 'read:org' ]

This code was taken from this issue https://github.com/sahat/satellizer/issues/658

antoinehoriot commented 8 years ago

Hi! I'm very new to satellizer so I might be doing something wrong but I'm trying to set up a login with Patreon button (OAuth2) and the only thing I'm able to get is the response code.

I'm running a simple Angularfire stack hosted on a Apache server.

sahat commented 8 years ago

@saqueib Are we both talking about the same console? You should be seeing that code output on your server, but I meant the JS console in your browser. It should print out those data values after you modified satellizer.js file.

saqueib commented 8 years ago

@sahat yes in chrome dev console I not getting anything, on server which is just below code for testing is giving me code only

http://localhost:3999 server code

// Get the request 
$data = json_encode($_REQUEST);
file_put_contents ( 'data.txt' , $data);
print_r($_REQUEST);
sahat commented 8 years ago

@saqueib Any luck with tracking down the problem?