laardee / serverless-authentication-boilerplate

Generic authentication boilerplate for Serverless framework
http://laardee.github.io/serverless-authentication-gh-pages
MIT License
568 stars 71 forks source link

How to redirect to originating page? #7

Closed rentrop closed 8 years ago

rentrop commented 8 years ago

Is there a way to redirect the user to his/her current position?

E.g. The user is on /cars. After he logs in i want him to be end up on /cars again. If he is on /watches i want him to be redirected to /watches.

As far as i understand

"redirectClientURI": "http://url-to-frontend-webapp/"

determins the redirect URI. How can i make something like "redirectClientURI": "origin" work?

laardee commented 8 years ago

@rentrop, maybe you could map header referer and use that as a redirectClientURI.

Here is a small example: https://jsfiddle.net/9t9kysaz/

In the Api Gateway I've mapped origin and referer (requestTemplates in s-function.json)

{
    "origin": "$input.params().header.origin",
    "referer": "$input.params().header.referer"
}

And then I have simple Lambda function that returns mapped data

exports.handler = function(event, context) {
    context.succeed(event);
};

When you save the state to DynamoDB on signinHandler, you could save also the referer. Then in the callbackHandler, where you compare the state returned from oauth provider, you could get the saved referer and pass { redirect_client_uri: referer, token_secret: providerConfig.token_secret } to utils.tokenResponse instead of providerConfig.

Does it make any sense?

rentrop commented 8 years ago

Perfect. Thank you i will work to make it happend