Giter VIP home page Giter VIP logo

Comments (9)

frankcarey avatar frankcarey commented on August 19, 2024 1

I've got this working by hacking loopback-component-passport module and adding custom code in the passport.authenticate() customCallback to add params of userId and access_token to the successRedirect url. This works fine except when I tried to do it the "right way" by passing in option.customCallback() (as I discovered was an option in the loopback-component-passport code).

The issue is that when passing in the customCallback vs hacking the module, it looses the scope on res, and req variables so I loose the ability to do the same redirects the default one does. Anyone find a solution to that so I don't have to hack the module?

See http://passportjs.org/guide/authenticate/

from loopback-component-passport.

frankcarey avatar frankcarey commented on August 19, 2024 1

Oh, and It might be a good idea to incorporate this as a built-in option as well.

from loopback-component-passport.

frankcarey avatar frankcarey commented on August 19, 2024

Any answer here? Do we need to add loopback.token as well?

from loopback-component-passport.

frankcarey avatar frankcarey commented on August 19, 2024
Is it possible somehow to redirect using AccessToken and UserId instead of session/cookie?

I've created a pull request that allows for at least overriding the defaults. The PR has some sample code for implementing a redirect with params as described.

#23

For those curious, my frontend code that grabs the params and then saves them using the angular sdk looks like this:

// Note that User is from lbServices / the autogenerated angular sdk.
angular.module('myApp')
  .controller('LoginCtrl', function ($scope, User, $location, $window) {
    // this is at a route of /login and is a page that shows a button/link that will redirect the user
    // to the proper oath provider.
    $scope.loginOauth = function(provider) {
      // Redirect the user to the api to follow the login flow of the loopback api.
      $window.location.href = "http://my.api.com/auth/" + provider;
    };
  })
  // Note that LoopBackAuth is from the lbServices as well.
  // This is at a route of /login/callback and the url will look something like..
  // /login/callback?access_token=somehash?userId=someuserid
  .controller('LoginCallbackCtrl', function ($scope, User, LoopBackAuth, $location, $window) {
    // Grab the params from the current url.
    var params = $location.search();

      // Handle response by adding properties to the LBAuth and then calling save
      LoopBackAuth.currentUserId = params.userId;
      LoopBackAuth.accessTokenId = params.access_token;
      // Note that you can also set LoopBackAuth.rememberMe which changes the storage from session to local.   

      // Saves the values to local storage.
      LoopBackAuth.save();

      // TODO we might want to grab the user info here as soon as they login.
      /*
      User.getCurrent(function(test) {
        console.log("success", test);
      },
      function(err) {
        console.log("fail", err);
      }               
      );
      */
      // Just redirect the user to the homepage once they are logged in.
      $location.url("/");
  });

from loopback-component-passport.

cajoy avatar cajoy commented on August 19, 2024

Absolutely agree with you - it should be integrated. And you did great job. But seems like package maintainers are very busy doing other stuffs ;)

from loopback-component-passport.

OwenBrotherwood avatar OwenBrotherwood commented on August 19, 2024

+1 interesting
If the maintainer sparks in, then I can join any effort.
headers contra cookies/urls is AAA country. strongloop/loopback#1338 @raymondfeng

from loopback-component-passport.

 avatar commented on August 19, 2024

+1

from loopback-component-passport.

aiampogi avatar aiampogi commented on August 19, 2024

+1 very nice idea to make it built-in

from loopback-component-passport.

stale avatar stale commented on August 19, 2024

This issue has been closed due to continued inactivity. Thank you for your understanding. If you believe this to be in error, please contact one of the code owners, listed in the CODEOWNERS file at the top-level of this repository.

from loopback-component-passport.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.