Microsoft OAuth Only Using Default Redirect URL

Hello!

I am working on a web application written in Typescript with separate client and server components. I am hosting deployed versions of this app in Azure and have configured Stych to support Email Magic Links and Microsoft OAuth. We are currently using the pre-built Stytch UI for our client.

There are no issues in the normal operating environment where the deployed client is communicating with the deployed server, nor when both are running locally. However, I’d like for my devs to be able to work on the client locally while using the deployed server. For that reason, I am specifying the login redirect URL for the magic link requests and have added both the local and the Azure URLS in the Stytch Dashboard.

The issue arises when trying to use Microsoft OAuth from the local client when communicating with the server running in Azure. My understanding is that process is supposed to determine which redirect URL to use based on where the request originates from, but it seems to always be sending me to the deployed instance, which is the default URL. If I set the localhost URL as default, then it works locally but now the deployed client tries to send me to localhost.

Is there some way for me to tell this OAuth process which redirect URL to use? Please let me know if you need any further info.

Thanks!

Hey Drew – thanks for posting!

You can include specific redirect URLs directly in your OAuth Start request, which you can set dynamically based on the environment you’re using. Which Stytch SDK are you using to call Microsoft OAuth Start? I’d be happy to provide an example code snippet!

Hey Nicole, thanks for the quick response!

I’m using the pre-built UI process specified here: Integrating OAuth for authentication using Stytch’s pre-built UI | Stytch B2B SaaS Authentication"

Like I said previously, I’m specifying the redirect URL for the magic links already but didn’t see any information on how to do that for OAuth in the docs. Help is very appreciated!

Hi @Drew_Nelson ,

You can set this via the loginRedirectURL and signupRedirectURL parameters under oauthOptions in your configuration!

More on this, and other supported parameters here (expand the config section): JavaScript SDK - UI config | Stytch B2B authentication

That worked perfectly, thank you!

I imported the StytchB2BUIConfig type for my config object which is letting me see the config options a bit more clearly now. Probably should have done that to begin with.

Thanks again!