# Blazor WASM Redirect URI

**URL:** <https://community.auth0.com/t/blazor-wasm-redirect-uri/99340>\
**Category:** Get Help\
**Tags:** new-universal-login-experience, login-experience\
**Created:** [January 31, 2023, 12:32am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340 "2023-01-31T00:32:57Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![nexusrob](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nexusrob/32/42897_2.png) [@nexusrob](https://community.auth0.com/u/nexusrob)\
**Post date:** [January 31, 2023, 12:32am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/1 "2023-01-31T00:32:58Z")

</div>

I see [here](https://auth0.com/docs/secure/attack-protection/state-parameters) that return\_uri is used to send a user to a page after authentication, and I have used this with success in React.

How do I do this with Blazor WASM? I have tried this with no success:

```auto
<a href="authentication/login?return_uri=/somepage">LOG IN</a>

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [January 31, 2023, 9:22am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/2 "2023-01-31T09:22:28Z")

</div>

Hey there!

Thanks for asking! Maybe our Blazor Genius @andrea.chiarelli will be able to help on that front! Thank you!

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [February 1, 2023, 9:43am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/3 "2023-02-01T09:43:02Z")

</div>

Hey @nexusrob,  
Maybe the parameter you are talking about is `redirect_uri`, not `return_uri`. See [here](https://auth0.com/docs/authenticate/login/redirect-users-after-login) for more details about this parameter.

This is the [standard OAuth2 parameter](https://auth0.com/docs/authenticate/protocols/oauth#authorization-endpoint) that you should use when talking directly to the authorization server, i.e. your Auth0 tenant in this case.

If your Blazor WASM application follows the architecture I discussed in [this article](https://auth0.com/blog/securing-blazor-webassembly-apps), the `authentication/login` endpoint is not an authentication server (i.e. Auth0) endpoint. It’s the endpoint of a page in your application (specifically, `Client/Pages/Authentication.razor`).

So, the `redirect_uri` parameter is ignored. The page relies on the default behavior of the `<RemoteAuthenticatorView>` component to interact with the authorization server. In this case, you have to use the `returnUrl` parameter with a fully qualified URL.

In other words, your link should look like the following:

```plaintext
<a href="authentication/login?returnUrl=https%3A%2F%2Flocalhost%3A7291%2Fsomepage">LOG IN</a>

```

Take a look at [Blazor documentation](https://learn.microsoft.com/en-us/aspnet/core/blazor/security/webassembly/standalone-with-authentication-library?view=aspnetcore-6.0#redirecttologin-component-1) for more details.

---

<div class="post-metadata">

**Author:** ![nexusrob](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nexusrob/32/42897_2.png) [@nexusrob](https://community.auth0.com/u/nexusrob)\
**Post date:** [February 2, 2023, 1:02am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/4 "2023-02-02T01:02:04Z")

</div>

Hi @andrea.chiarelli

I did indeed follow your article and I do have Authentication.razor. I have also changed my anchor tag to use `returnUrl`, but I still end up on my home page after authentication completes.

I tried this for the anchor tag

`<a href="authentication/login?returnUrl=https%3A%2F%2Fwww.google.com">LOG IN</a>`

When I land on the google account selection page, the URL contains

`redirect_uri=https%3A%2F%2F<<MYAUTHORITY>>%2Flogin%2Fcallback`

regardless of what is in the `returnUrl` parameter I set

Do I maybe need to add something to the authentication component in order to handle the redirect in a custom manner?

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [February 2, 2023, 11:34am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/5 "2023-02-02T11:34:06Z")

</div>

Hey @nexusrob,  
You can’t just use any URL as a `returnUrl`. It must have the same origin as your application.  
Also, if you put Google’s home page as the value for `returnUrl`, the login process shouldn’t even start, so I don’t understand when you say “When I land on the google account selection page…” 🤔

Taking [my sample project](https://github.com/auth0-blog/secure-blazor-wasm-quiz-manager) as our reference, the only change you need to make is related to `AccessControl.razor`. It should have the following highlighted line:

```auto
//... other stuff...

<AuthorizeView>
    <Authorized>
        Hello, @context.User.Identity.Name!
        <a href="#" @onclick="BeginSignOut">Log out</a>
    </Authorized>
    <NotAuthorized>
👉👉👉 <a href="authentication/login?returnUrl=https%3A%2F%2Flocalhost%3A7291%2FquizViewer">Log in</a>
    </NotAuthorized>
</AuthorizeView>

// ...other stuf...

```

Please, download a copy of the project and apply the change to make a test. I tried and it works correctly.

---

<div class="post-metadata">

**Author:** ![nexusrob](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nexusrob/32/42897_2.png) [@nexusrob](https://community.auth0.com/u/nexusrob)\
**Post date:** [February 2, 2023, 12:43pm UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/6 "2023-02-02T12:43:48Z")

</div>

I just put [google.com](http://google.com) as I didnt want to post my Auth0 audience URL on here.

By “When I land on the google account selection page…” what I mean is when I click the login link, it goes to Auth0 fine, I choose “log in with Google”, it then takes me to my Google account selection screen, and it has

`redirect_uri=https%3A%2F%2F<<MYAUTHORITY>>%2Flogin%2Fcallback`

in the URL, even though my anchor tag is like this

`<a href="authentication/login?returnUrl=https%3A%2F%2Fwww.nexusbet.co.uk%2Foffers">LOG IN</a>`

Then after authentication I end up on my home page.

So I can’t see what I have missed as it seems to match the samples and article.

---

<div class="post-metadata">

**Author:** ![andrea.chiarelli](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/andrea.chiarelli/32/16034_2.png) [@andrea.chiarelli](https://community.auth0.com/u/andrea.chiarelli)\
**Post date:** [February 3, 2023, 8:25am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/7 "2023-02-03T08:25:29Z")

</div>

Sorry for this. Unfortunately, I can’t figure out what’s happening. As far as I know, it should be working

---

<div class="post-metadata">

**Author:** ![nexusrob](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/nexusrob/32/42897_2.png) [@nexusrob](https://community.auth0.com/u/nexusrob)\
**Post date:** [February 20, 2023, 11:36pm UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/9 "2023-02-20T23:36:16Z")

</div>

I found the solution; the ReturnUrl needs to be specified on the initial redirect, and using NavigateToLogin.

```auto
InteractiveRequestOptions requestOptions = new()
{
    Interaction = InteractionType.SignIn,
    ReturnUrl = "/my-page",
};

navManager.NavigateToLogin("authentication/login", requestOptions);

```

---

<div class="post-metadata">

**Author:** ![konrad.sopala](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/konrad.sopala/32/13516_2.png) [@konrad.sopala](https://community.auth0.com/u/konrad.sopala)\
**Post date:** [February 21, 2023, 10:07am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/10 "2023-02-21T10:07:01Z")

</div>

Woooohooo! Perfect! Thanks for sharing it with the rest of community!

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [March 7, 2023, 10:07am UTC](https://community.auth0.com/t/blazor-wasm-redirect-uri/99340/11 "2023-03-07T10:07:36Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
