-
Notifications
You must be signed in to change notification settings - Fork 927
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
auth stuck at the callback URL — not storing Auth0 token [SPA mode] #536
Comments
I have the exact same issue just with custom OAuth routing. If you'll happen to find a solution please mention me. Thanks in advance ^^ |
Mode SPA — auth-module repositoryTo ensure it wasn't an issue only on Reproduction link Steps to reproduce
Same as above, when running auth-module development mode with No errors are shown in console. |
Mode SSR (universal) — auth-module repositorySteps 1 and 2 same as #536 (comment)
I'm making separate comments in the hope to more clearly separate the different tests I've done. I am now prone to believe that either:
|
After a whole day researching I stumbled upon these issues #299 and nuxt/nuxt#5267. The whole situation is still somewhat unclear to me, however I've tried to deploy the application in another way again Mode SSR (spa) — auth-module repository and the authentication flow worked as expected. As referenced in the above mentioned issues it seems that static SPA mode is not supported at all by the auth-module (more specifically by its dynamic behaviour, so other libraries could be affected). What it is not explain at all in the documentation is that there are two possible ways to serve an SPA application:
In either case,
From the documentation on SPA one would assume that deploying only the I am hella lot confused on the deployment process involved with Nuxt. I beg someone to explain what's happening here. |
After some tests on my side it seems to me that on SPA mode, on initial load (first page or hard refresh), the route (and maybe some other elements) are not properly initialized when passed to the middleware. I wonder if others have noticed the same issue. EDIT |
Its not working for me either, netlify + auth0 mode spa, on local it's working, deployed generated version not |
No clue either, but check #299 (comment) |
Same here. Nuxt deployed on Netlify. Redirect occurs (after adding trailing slash to callback) but in the store all relevant data for auth is null. |
My solution was to move my app from Netlify to Heroku. I changed the mode to universal and now although out of my favorite hosting company, I benefit from SSR. =) And the auth module is working like a charm. |
The Nuxt community has a strong focus on SSR and sometimes the likes of us that need just a SPA can feel a little left behind... |
This is my solution to host on Zeit/Now and login using github: now.json
functions/authorize.js
It's just a serverless function who overrides |
Hi Fellow users I have submitted a PR with a potential fix #586 (it fixed my login flow which has same issue), can some of you please try the fix and confirm if it fixes your issue too (or not). Thanks |
I was about to test it out but it has already been merged! So I suppose it's go from the devs too! I've updated my first post to reflect the new updates on the subject.
|
thank you. will wait for you to confirm as well. I have also requested to cut a new release with this fix (if its not too much to ask). |
I am having the same issue with google auth. auth/module 4.9.1 |
I think for google auth, u need authorize endpoint. One of the comment above talks about setting that for github auth case and also talks about how netlify redirect can solve it May be that is the issue? |
For me switching to nuxtjs/auth-next in combination with this: nuxt/nuxt#5800 (comment) |
I had trouble where callback url was configured for an oauth strategy but didn't match $auth.options.redirect.callback so the middleware wasn't extracting tokens from url fragment. Hope this helps someone else. |
see also Safari/Webkit - This can affect the code:
Checked - indeed this problem is specific to Safari. |
At first place, thanks for this awesome module. Ended up with something like this in my callback.vue: export default {
auth: false,
mounted: async function () {
const hash = this.parseQuery(this.$auth.ctx.route.hash.substr(1));
const parsedQuery = Object.assign({}, this.$auth.ctx.route.query, hash);
var strategy = this.$auth.getStrategy();
let token = parsedQuery[strategy.options.token.property];
let refreshToken;
if (strategy.refreshToken.property) {
refreshToken = parsedQuery[strategy.options.refreshToken.property];
}
const state = this.$auth.$storage.getUniversal(
strategy.options.name + ".state"
);
this.$auth.$storage.setUniversal(strategy.options.name + ".state", null);
if (state && parsedQuery.state !== state) {
return;
}
if (strategy.options.responseType === "code" && parsedQuery.code) {
let codeVerifier;
if (
strategy.options.codeChallengeMethod &&
strategy.options.codeChallengeMethod !== "implicit"
) {
codeVerifier = this.$auth.$storage.getUniversal(
strategy.options.name + ".pkce_code_verifier"
);
this.$auth.$storage.setUniversal(
strategy.options.name + ".pkce_code_verifier",
null
);
}
const response = await this.$auth.request({
method: "post",
url: strategy.options.endpoints.token,
baseURL: "",
data: this.encodeQuery({
code: parsedQuery.code,
client_id: strategy.options.clientId + "",
redirect_uri: strategy.redirectURI,
response_type: strategy.options.responseType,
audience: strategy.options.audience,
grant_type: strategy.options.grantType,
code_verifier: codeVerifier,
}),
});
token =
this.getProp(response.data, strategy.options.token.property) || token;
refreshToken =
this.getProp(response.data, strategy.options.refreshToken.property) ||
refreshToken;
}
if (!token || !token.length) {
return;
}
strategy.token.set(token);
if (refreshToken && refreshToken.length) {
strategy.refreshToken.set(refreshToken);
}
this.$auth.redirect("home", true);
},
methods: {
parseQuery(queryString) {
const query = {};
const pairs = queryString.split("&");
for (let i = 0; i < pairs.length; i++) {
const pair = pairs[i].split("=");
query[decodeURIComponent(pair[0])] = decodeURIComponent(pair[1] || "");
}
return query;
},
encodeQuery(queryObject) {
return Object.entries(queryObject)
.filter(([_key, value]) => typeof value !== "undefined")
.map(
([key, value]) =>
encodeURIComponent(key) +
(value != null ? "=" + encodeURIComponent(value) : "")
)
.join("&");
},
getProp(holder, propName) {
if (!propName || !holder || typeof holder !== "object") {
return holder;
}
if (propName in holder) {
return holder[propName];
}
const propParts = Array.isArray(propName)
? propName
: (propName + "").split(".");
let result = holder;
while (propParts.length && result) {
result = result[propParts.shift()];
}
return result;
},
},
}; Hope this may help anyone. |
Thanks to r3dqu33n! I use Google OAuth2 provider in @nuxtjs/auth-next for authentication. Google makes callback to "/login" and the static site made with "nuxt generate" just does not have the page for it generated. I was already studying how to copy the module's code for callback into my own page login.vue when I came across r3dqu33n's code. |
I got similar issue fixed by changing token url
hope it helps someone. complete auth config
|
@prajintst where do you make that change? please can you mention file name etc |
|
Since auth-next seems to resolve this problem, closing out the issue. |
EDIT
All the testing links are not working anymore. Given the feedback and the PR made it seems the issue is solved so I took offline the demos I made for the various scenarios. I will check out the new PR too as soon as I can but given that the project maintainers already merged it to master I suppose it's a go for production too.
Given the three tests I've done, I am making here a recap for clarity
Reproduction link: https://nuxt.federicod.dev/
Application stays stuck at the callback page, not storing the auth0 token, in the chance that this was an issue with the example-auth0 repo alone I've tested also the example build in the auth-module repo.
Reproduction link: https://auth-test.federicod.dev/
Same as above, I now think that the issue resides indeed in the auth-module itself.
Reproduction link: https://auth-test-ssr.federicod.dev/
After trying to build the SSR version of the example\demo application, and serving it with
nuxt start
I have confirmed that the auth-module either:Mode SPA — example-auth0 repository
Version
v4.8.5
Reproduction link
https://nuxt.federicod.dev/
Steps to reproduce
git clone https://github.com/nuxt/example-auth0.git
;domain
andclient_id
intonuxt.config.js
(I am not using the .env file as it seems to me that it doesn't get embedded in the SPA after running npm run build)spa
On a more complicated platform I am developing, some API calls that are made on the callback URL to populate a Vuex store all yields unauthorized error, meaning that the token doesn't get stored at all.
When running example-auth0 and the application I am developing in development mode with
npm run dev
, everything works fine. So I suppose that something goes wrong only after running the build command.What is expected ?
I expect the callback URL to be opened and the token received stored.
What is actually happening?
The SPA stays stuck at the callback URL and no token is stored.
Additional comments?
Webserver: Caddy
Configuration:
No errors are shown in the console.
The text was updated successfully, but these errors were encountered: