Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optionally pass accessToken as a parameter to returnTo #102

Closed
gausie opened this issue Nov 5, 2015 · 4 comments
Closed

Optionally pass accessToken as a parameter to returnTo #102

gausie opened this issue Nov 5, 2015 · 4 comments
Labels

Comments

@gausie
Copy link
Contributor

gausie commented Nov 5, 2015

On mobile devices, it is useful to have the login redirect to a URL with a custom protocol (myapp://) so that the intent can be captured and the login processed. In 1.6.0 we have the ability to set a returnTo session key for the successRedirect.

It would be extremely useful to be able to append the accessToken generated from a successful login to this URL as query parameters, as they can be read by a mobile application.

@jonathan-casarrubias
Copy link

when you configure the passport provider you set the success url, set that as a middleware in the backend like

"successRedirect": "/auth/account"

then just create a middleware like

app.get('/auth/account', function (req, res, next) {
        app.models.Account.findById(req.accessToken.userId, function(err, account) {
            if (err) { next(err); }
            res.redirect('http://yourdomain.com?accessToken=' + req.accessToken.id + '&userId=' + account.id);
        });
    });

@loay loay added the triage label Nov 16, 2015
@loay loay self-assigned this Nov 16, 2015
@loay loay added the waiting label Nov 16, 2015
@anupvarghese
Copy link

Thanks @jonathan-casarrubias this is a good suggestion.

This looks like a good option for SPA login. I am using it as below in my react client app,
Login.jsx

import React from 'react';
class Login extends React.Component {
render() {
    const googleLogin = () => {
      window.open('http://localhost:3000/auth/google'); // Do some modifications for window close on successful login or cancel clicks
  };
}
return (
  <div>
    ........
    <a href="#" onClick={googleLogin}>Google +</a>
  <div>
  );
}

at server.js in loopback app

app.get('/auth/account', function(req, res, next) {
  console.log(req.accessToken);
  //res.json(req.accessToken);
  res.redirect(301,'http://localhost:8080/dashboard?accessToken=' + req.accessToken.id);
});

Is it possible to create a middleware in the failure case also?

@stale
Copy link

stale bot commented Aug 23, 2017

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot closed this as completed Sep 6, 2017
@stale
Copy link

stale bot commented Sep 6, 2017

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

6 participants