-
-
Notifications
You must be signed in to change notification settings - Fork 753
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
Set oAuth redirect URL dynamically #1591
Comments
All methods can be easily customized by overriding them in your own class which is documented here and also shown with a GitHub login in the guide. In your case by overriding the class MyDynamicRedirectStrategy extends OAuthStrategy {
async getRedirect(authResult) {
const { user } = authResult;
// Get the redirect url e.g. from the users organization
const { redirectUrl } = await app.service('organizations').get(user.organizationId);
// This is necessary if it should work with the standard Authentication
// client (which could be customized as well)
const query = authResult.accessToken ? {
access_token: authResult.accessToken
} : {
error: data.message || 'OAuth Authentication not successful'
};
return `https://${redirectUrl}#${querystring.stringify(query)}`;
}
}
// ...
authentication.register('github', new MyDynamicRedirectStrategy()); |
@daffl |
I'm assuming this is what Grants dynamic overrides are for. |
@daffl |
Got it. This is probably a bug since the bodyParser is missing and the URL hasn't been documented yet. This is probably also the same issue as in #1387. |
What provider is this and what redirect URL do you want to set? |
@daffl
|
Ok, that makes sense. Probably means the rest of the query in https://github.com/feathersjs/feathers/blob/master/packages/authentication-oauth/src/express.ts#L34 needs to be stored in the session and then passed as |
Question (from slack): Lets say I have multiple javascript apps (each on different domains). How can I have each of them redirect correctly but re-use existing oauth providers, like lets say I want to have app1.domain.com and app2.domain.com both be able to login to my app through google oauth. Consider this: CustomOauthProvider.js: async getRedirec(authResult, params){
const url = prams.redirect;
const validAppService = this.app.service('apps');
const appConfig = await validAppService.find({ url })[0];
if(!url){
throw new Error('this is not a valid redirect')
}
return url;
}
// another scenario
async getRedirec(authResult, params){
const appId = prams.appId;
const validAppService = this.app.service('apps');
const appConfig = await validAppService.find({ appId })[0];
if(!appConfig){
throw new Error('this is not a valid appId')
}
// additional logic might check to see if user can login to this app
return appConfig.redirect;
} |
Just revisiting this a little bit - I think this is sort of what I'd like to do with my feathers/client apps -> basically register an application and its redirect URI - it could be a custom uri scheme or a different domain based url, like I don't believe this would currently work, it looks like it only works with paths on the same domain. Would that be something that feathers could work with? I could take a stab at a pull request. |
You can already do this by passing the additional information through the flow via the This issue can also be closed, since it is now possible by setting the |
I have my app on When I directly access class GoogleStrategy extends OAuthStrategy {
async getRedirect (data) {
const appURL = app.get('appURL')
return `${appURL}#accessToken=${data.accessToken}&strategy=${data.authentication.strategy}`
}
... So I'm able log him in, with accessToken. In my
However
I receive an error from Google: `Error: redirect_uri_mismatch The redirect URI in the request, https://app.somedomain.com/oauth/google/callback, does not match the ones authorized for the OAuth client.` So it seems, in this case to use the referrer and not the data from the |
There are two different redirect URLs. The |
thank you, to clarify this, I'm very new to oauth, so maybe I'm doing something wrong... The host in app.somedomain.com does not exist anywhere in my feathers code, so I really don't understand why feather is setting this as redirect uri, when I click on the link... This is why I supposed it must be related to the refererrer somehow... So if understand correctly, usually the redirect is constructed with the host information from default.json? I'll try to investigate then, in this direction... |
Steps to reproduce
I'm working on a project where I need to set the oAuth redirect URL dynamically (I need to set the domain or subdomain dynamically). I've read that this is possible in the latest version of Feathers (#990). However, I've struggled to make this work in practice. Looking at the code, it seems that it is not possible to dynamically set the redirect URL -- what I see in the code here just uses the redirect URL from the environment variables: https://github.com/feathersjs/feathers/blob/master/packages/authentication-oauth/src/strategy.ts#L75
Expected behavior
I'd like to be able to dynamically set the redirect URL, changing the domain or subdomain. This seems to be possible with Grant directly, but I can't see how to do this with Feathers.
Actual behavior
I can't see any way to do this! Would really appreciate your advice on how to do this (if it's possible)
System configuration
Tell us about the applicable parts of your setup.
Module versions (especially the part that's not working):
Feathers v4 (latest)
The text was updated successfully, but these errors were encountered: