Angular JS + Node JS + Passport + Spring OAuth2 Authentication/Authorization

前端 未结 1 632
一生所求
一生所求 2021-02-04 12:08

I am new to PassportJS and AngularJS and I have a doubt about how to proceed with this authorization.

I have Spring REST API Secured by Oauth2, but I have to send togeth

相关标签:
1条回答
  • 2021-02-04 12:37

    I do not know if I have to use passport-Bearer or not and how to use-it.

    No. There are other options, such as:

    • oauth.io

    • httpProvider + express middleware

    Here is an example of how to use passport:

    // Express using passport-local
    // This code is adaptation of examples/express3 from https://github.com/jaredhanson/passport-local
    
    
    // configure Express
    app.configure(function() {
    // ...
    app.use(express.session({
    // The domain should start with a dot, as this allows the subdomain.
    domain: '.app.local',
    secret: 'keyboard cat'
    }));
    
    // Enable cors.
    app.use(function(req, res, next) {
    res.header('Access-Control-Allow-Credentials', true);
    res.header('Access-Control-Allow-Origin', req.headers.origin);
    res.header('Access-Control-Allow-Methods', 'GET,PUT,POST,DELETE');
    res.header('Access-Control-Allow-Headers', 'X-Requested-With, X-HTTP-Method-Override, Content-Type, Accept');
    next();
    });
    
    // ...
    });
    
    app.get('/account', ensureAuthenticated, function(req, res){
    // Return the current user's info
    res.json(req.user);
    });
    

    References

    • Express + AngularJS Subdomain login
    0 讨论(0)
提交回复
热议问题