Skip to content

Commit f09c740

Browse files
authored
Merge pull request #50604 from cephalin/issue11692
sign-out & URL fragment info
2 parents 3caf39a + 8beef84 commit f09c740

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

articles/app-service/app-service-authentication-how-to.md

Lines changed: 46 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@ To get started quickly, see one of the following tutorials:
3030
* [How to configure your app to use Microsoft Account login](app-service-mobile-how-to-configure-microsoft-authentication.md)
3131
* [How to configure your app to use Twitter login](app-service-mobile-how-to-configure-twitter-authentication.md)
3232

33-
## Configure multiple sign-in options
33+
## Use multiple sign-in providers
3434

35-
The portal configuration doesn't offer a turn-key way to present multiple sign-in options to your users (such as both Facebook and Twitter). However, it isn't difficult to add the functionality to your web app. The steps are outlined as follows:
35+
The portal configuration doesn't offer a turn-key way to present multiple sign-in providers to your users (such as both Facebook and Twitter). However, it isn't difficult to add the functionality to your web app. The steps are outlined as follows:
3636

3737
First, in the **Authentication / Authorization** page in the Azure portal, configure each of the identity provider you want to enable.
3838

@@ -56,6 +56,50 @@ To redirect the user post-sign-in to a custom URL, use the `post_login_redirect_
5656
<a href="/.auth/login/<provider>?post_login_redirect_url=/Home/Index">Log in</a>
5757
```
5858

59+
## Sign out of a session
60+
61+
Users can initiate a sign-out by sending a `GET` request to the app's `/.auth/logout` endpoint. The `GET` request does the following:
62+
63+
- Clears authentication cookies from the current session.
64+
- Deletes the current user's tokens from the token store.
65+
- For Azure Active Directory and Google, performs a server-side sign-out on the identity provider.
66+
67+
Here's a simple sign-out link in a webpage:
68+
69+
```HTML
70+
<a href="/.auth/logout">Sign out</a>
71+
```
72+
73+
By default, a successful sign-out redirects the client to the URL `/.auth/logout/done`. You can change the post-sign-out redirect page by adding the `post_logout_redirect_uri` query parameter. For example:
74+
75+
```
76+
GET /.auth/logout?post_logout_redirect_uri=/index.html
77+
```
78+
79+
It's recommended that you [encode](https://wikipedia.org/wiki/Percent-encoding) the value of `post_logout_redirect_uri`.
80+
81+
When using fully qualified URLs, the URL must be either hosted in the same domain or configured as an allowed external redirect URL for your app. In the following example, to redirect to `https://myexternalurl.com` that's not hosted in the same domain:
82+
83+
```
84+
GET /.auth/logout?post_logout_redirect_uri=https%3A%2F%2Fmyexternalurl.com
85+
```
86+
87+
You must run the following command in the [Azure Cloud Shell](../cloud-shell/quickstart.md):
88+
89+
```azurecli-interactive
90+
az webapp auth update --name <app_name> --resource-group <group_name> --allowed-external-redirect-urls "https://myexternalurl.com"
91+
```
92+
93+
## Preserve URL fragments
94+
95+
After users sign in to your app, they usually want to be redirected to the same section of the same page, such as `/wiki/Main_Page#SectionZ`. However, because [URL fragments](https://wikipedia.org/wiki/Fragment_identifier) (for example, `#SectionZ`) are never sent to the server, they are not preserved by default after the OAuth sign-in completes and redirects back to your app. Users then get a suboptimal experience when they need to navigate to the desired anchor again. This limitation applies to all server-side authentication solutions.
96+
97+
In App Service authentication, you can preserve URL fragments across the OAuth sign-in. To do this, set an app setting called `WEBSITE_AUTH_PRESERVE_URL_FRAGMENT` to `true`. You can do it in the [Azure portal](https://portal.azure.com), or simply run the following command in the [Azure Cloud Shell](../cloud-shell/quickstart.md):
98+
99+
```azurecli-interactive
100+
az webapp config appsettings set --name <app_name> --resource-group <group_name> --settings WEBSITE_AUTH_PRESERVE_URL_FRAGMENT="true"
101+
```
102+
59103
## Access user claims
60104

61105
App Service passes user claims to your application by using special headers. External requests aren't allowed to set these headers, so they are present only if set by App Service. Some example headers include:

articles/app-service/app-service-authentication-overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ With this option, you don't need to write any authentication code in your app. F
131131

132132
The option is **Allow Anonymous requests**. This option turns on authentication and authorization in App Service, but defers authorization decisions to your application code. For authenticated requests, App Service also passes along authentication information in the HTTP headers.
133133

134-
This option provides more flexibility in handling anonymous requests. For example, it lets you [present multiple sign-in options](app-service-authentication-how-to.md#configure-multiple-sign-in-options) to your users. However, you have to write code.
134+
This option provides more flexibility in handling anonymous requests. For example, it lets you [present multiple sign-in providers](app-service-authentication-how-to.md#use-multiple-sign-in-providers) to your users. However, you must write code.
135135

136136
## More resources
137137

0 commit comments

Comments
 (0)