question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to redirect from vue3 to grant/express through axios?

See original GitHub issue

I am using vue3 as my front-end. If, therefore, my oauth2 callback goes directly to express.js/grant, my front-end doesn’t know about it and cannot act upon the authentication result. Therefore my oauth2 callback with the ?access_token=... has to land on the vue3 front end and then be somehow routed/redirected to Express.js through some axios call. Express.js/grant will then complete the authentication by exchanging the code for a token and user/profile and return it to the front end through the axios response. When I do that, I get: GET | http://localhost:5000/?error=Grant: missing session or misconfigured provider I am guessing that some “session” information that was created when I made the original request to the grant/express backend is now missing from the axios/vue3 call. Any ideas on how to resolve this?

Issue Analytics

  • State:closed
  • Created 2 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
simovcommented, Jan 29, 2022

Ok, here are some general concepts about it then:

Axios or any other HTTP client cannot be used for this. The user have to click on a regular link pointing to your Grant OAuth proxy, usually available on the /connect/[provider] route. This will allow the browser to navigate away from your single page Vua app and into the third-party authorization server page, where the user can login with that provider.

After that you have a few transport options to pick from, but maybe the easier for you would be to set your callback route to point back to your single page Vue app. With that when the OAuth flow is complete the user will be redirected all the way back to your single page Vue app and the resulting access_token will be embedded into the URL in the address bar as querystring.

After the page loads you can use JavaScript in your single page Vua app to read the access_token from the querystring.

There are other ways to achieve this as well, but you can try this one first as probably the easiest one to setup.

0reactions
simovcommented, Jan 30, 2022

That’s true. For that reason there are other transport types available such as session and state. If you take a look at the state transport example you will see that you can have a handler right after the Grant middleware where you can read the returned credentials, the access_token, probably store it in a database, and respond with something else, or redirect to another location in your frontend app.

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to redirect to another component in vue 3 using AXIOS ...
Assuming your code is something like. const response = await axios.post("<url>"); You can check with if (response.status === 200) .
Read more >
How to consume APIs with Vuex, Pinia, and Axios
In this article, you'll learn how to consume APIs from a server using Vuex, Pinia, and Axios. We'll cover the following sections: Using...
Read more >
Vue JS 3 Tutorial for Beginners #6 - Using Axios to ... - YouTube
Vue JS 3 Tutorial for Beginners #6 - Using Axios to Consume APIs in Vue 3.
Read more >
Getting Started With Axios In Nuxt - Smashing Magazine
In this tutorial, we will learn how to make a request in our Nuxt.js applications using the Axios module. We will also learn...
Read more >
Custom Error Pages based on API Response with Vue Router ...
Using Vue Router we will redirect to a custom error page that we will create. Create Vue App. We are going to use...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found