-
-
Notifications
You must be signed in to change notification settings - Fork 7.6k
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
Cannot get any authentication provider to work: redirect_uri_mismatch #6570
Comments
Hello @alexdevmotion, we have experienced a similar issue. In our case we did overwrite the To fix this issue we've updated the Auth.js with the updated version found under
Hope this will resolve the problem for you and anyone else who is facing a similar issue. |
@anis-marrouchi I don't have a But from your code snippet, I deduce that By the way, it wasn't related to the version, I had the same issue w/ 3.0.0. Thanks! Later edit
I'll investigate further. Laterer edit Can someone help shed some light on this issue? |
Hi @alexdevmotion, there is a better solution than changing the node modules file. |
@Kabil-Boutou I would clearly not go with the approach of modifying a file inside Setting the Thanks! |
@alexdevmotion did you find a fix. I am also stuck at this issue. After migrating my oauth is not working. Added url but the problem is after authentication redirection i am not getting JSON instead getting query parameters of id_token etc. The user is not saved at all. |
Nope I have not, I'm still waiting from feedback from other contributors. However, it seems that the problem you are encountering @akhilmhdh is different. |
Hi! You can set
|
I found that setting 'url' changes the url strapi admin should also point to. This could be an issue if the callback url points to a url that is not strapi e.g. if you set url as
then strapi thinks that https://760bbe10e952.ngrok.io/admin point to http://localhost:1337/admin |
I've just made a PR to fix this for github, facebook and google. May need fixing the rest. Also, I created a file called provider.js under ./config
This allow to override values in the user-permission plugin |
Are there any temporary fix for this without changing the |
You can copy the changed files and place them ./extensions/user-permissions/** |
grantConfig[provider].redirect_uri = `${strapi.config.server.url}/connect/${provider}/callback`; I think |
@iicdii in the pull request made, I suggested the following change: |
@reubenkcoutinho That will solve the problem. |
For now, I just created 'use strict';
/**
* Auth.js controller
*
* @description: A set of functions called "actions" for managing `Auth`.
*/
/* eslint-disable no-useless-escape */
const _ = require('lodash');
const grant = require('grant-koa');
module.exports = {
async connect(ctx, next) {
const grantConfig = await strapi
.store({
environment: '',
type: 'plugin',
name: 'users-permissions',
key: 'grant',
})
.get();
const [requestPath] = ctx.request.url.split('?');
const provider = requestPath.split('/')[2];
if (!_.get(grantConfig[provider], 'enabled')) {
return ctx.badRequest(null, 'This provider is disabled.');
}
// Ability to pass OAuth callback dynamically
grantConfig[provider].callback = _.get(ctx, 'query.callback') || grantConfig[provider].callback;
grantConfig[provider].redirect_uri = grantConfig[provider].redirect_uri || `${strapi.config.server.url}/connect/${provider}/callback`;
return grant(grantConfig)(ctx, next);
},
}; If you already set redirect uri in admin panel it will work. |
Just found this! |
@akhilmhdh I'm facing the same issue - did manage to make any progress on this? |
@jonathanmach Yah i fixed it. Basically i did exactly as you given above. Added my domain host and port as url in env format for production and development. Then it changed relative to absolute for callback. Ohhhh ok I think i know what your all bothered. Ok so basically the redirect uri is not what you think it is. The redirect url must be provider/auth/callback. Then your user will be saved properly. In front end after auth your will get an ID send that to this url. You will get json formated data of your user with jwt. https://blog.strapi.io/protected-routes-and-authentication-with-react-and-node-js/ Check this tutorial. Go to Here is the flow: section. You will get your ans there. |
@akhilmhdh YOU ARE A LIFE SAVIOR! Thank you once again! |
@jonathanmach Lol sure man ✌️ |
After setting url in config/env/production/server.js admin in production stop working.. Do you have any ideas how to fix it? |
Hi, can you specify what uses localhost:1337 as request url? |
@petersg83 The
That is why the |
Should there be a user created in strapi after successful authentication? I am using the GitHub provider and I am able to go through the authentication flow by setting |
Please check this file in the PR - https://github.com/strapi/strapi/pull/7132/files#diff-8434e8f791257802c2af54d99bc2f32d |
This issue has been mentioned on Strapi Community Forum. There might be relevant details there: https://forum.strapi.io/t/use-of-jwt-in-httponly-cookie-4632/1865/6 |
Describe the bug
I followed the documentation, I tried using the react-login-front-end-app, no matter how hard I try, I always run into the same redirect_uri_mismatch error.
Steps to reproduce the behavior
Expected behavior
Successful authentication
Screenshots
See in Additional context
System
Additional context
Seems to be a problem with how strapi is sending the redirect_uri to the Oauth providers. Shouldn't it be something like https://760bbe10e952.ngrok.io/connect/github/callback ?
I also noticed that, as opposed to the tutorial video, redirect URL field in the provider config doesn't get automatically populated, could it be a frontend issue?
If I try any other provider (tried facebook & google as well), I also get an URL related error.
The text was updated successfully, but these errors were encountered: