oauth-io/sdk-node

dynamic provider parameter

Closed this issue · 2 comments

I want to authorise multiple providers on my app and I'm just wondering if there is a way of doing it without having to create a separate endpoint for each one.

Something like this is what I'm after but the authorisation function doesn't seem to work when wrapped in a container function.

app.get('/signin', function(req, res){
OAuth.auth(req.param.provider, 'http://localhost:8080/oauth/redirect')
});

thyb commented

Yes, as OAuth.auth(provider, url) return a function(req,res) { ... } to handle the request, you have to call it manually:

app.get('/signin/:provider', function(req, res) {
  OAuth.auth(req.param.provider, 'http://localhost:8080/oauth/redirect')(req, res);
});

Thanks thyb that's working perfectly!