Comments (9)
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.
Oh, and It might be a good idea to incorporate this as a built-in option as well.
from loopback-component-passport.
Any answer here? Do we need to add loopback.token as well?
from loopback-component-passport.
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.
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.
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.
+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.
+1
from loopback-component-passport.
+1 very nice idea to make it built-in
from loopback-component-passport.
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)
- Cannot mix email and username to log in HOT 2
- Picking random user identity if profile.id or profile.openId is not set HOT 10
- Integration of auth by API Key / lifetime token HOT 2
- buildUserLdapProfile() patch HOT 4
- The `ApplicationCredential` instance is not valid. Details: `provider` can't be blank
- passportConfigurator.setupModels() is not working with my custom userModel. HOT 3
- options.callbackHTTPMethod can only be set to "post" or "get" HOT 2
- Missing loopback dependency HOT 6
- enable state in oauth2 HOT 3
- Does not support eternal Access Token with ttl=-1 HOT 2
- Swagger Documentation for Thirdparty auth api's for LDAP HOT 6
- when credentials are being updated, they delete the refresh token HOT 2
- Support for alternative Passport Strategies HOT 19
- How to link the same user's accounts (same email) instead of duplicating it? HOT 5
- ms-ad not getting all groups user is memberOf HOT 4
- Compatibility with loopback 4 HOT 4
- Realm is not supported when looking up existing players HOT 3
- Error 500 facebook/auth with random users HOT 2
- Passport does not work with OneLogin using the openid-connect package HOT 1
- Make sameSite cookie property configurable HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from loopback-component-passport.