Skip to content

Commit 39c3be1

Browse files
authored
Merge pull request #178940 from alexbuckgit/alexbuckgit/formatting-20211107
Code formatting improvements
2 parents c8b33d4 + 162d4d6 commit 39c3be1

File tree

1 file changed

+18
-15
lines changed

1 file changed

+18
-15
lines changed

articles/active-directory/develop/howto-build-services-resilient-to-metadata-refresh.md

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -30,18 +30,18 @@ Use latest version of [Microsoft.IdentityModel.*](https://www.nuget.org/packages
3030
In the `ConfigureServices` method of the Startup.cs, ensure that `JwtBearerOptions.RefreshOnIssuerKeyNotFound` is set to true, and that you're using the latest Microsoft.IdentityModel.* library. This property should be enabled by default.
3131

3232
```csharp
33-
services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options =>
34-
{
35-
36-
// shouldn’t be necessary as it’s true by default
37-
options.RefreshOnIssuerKeyNotFound = true;
38-
39-
};
33+
services.Configure<JwtBearerOptions>(AzureADDefaults.JwtBearerAuthenticationScheme, options =>
34+
{
35+
36+
// shouldn’t be necessary as it’s true by default
37+
options.RefreshOnIssuerKeyNotFound = true;
38+
39+
};
4040
```
4141

4242
## ASP.NET/ OWIN
4343

44-
Microsoft recommends that you move to ASP.NET Core, as development has stopped on ASP.NET.
44+
Microsoft recommends that you move to ASP.NET Core, as development has stopped on ASP.NET.
4545

4646
If you're using ASP.NET classic, use the latest [Microsoft.IdentityModel.*](https://www.nuget.org/packages?q=Microsoft.IdentityModel).
4747

@@ -52,18 +52,20 @@ OWIN has an automatic 24-hour refresh interval for the `OpenIdConnectConfigurati
5252
If you validate your token yourself, for instance in an Azure Function, use the latest version of [Microsoft.IdentityModel.*](https://www.nuget.org/packages?q=Microsoft.IdentityModel) and follow the metadata guidance illustrated by the code snippets below.
5353
5454
```csharp
55-
ConfigurationManager<OpenIdConnectConfiguration> configManager =
56-
new ConfigurationManager<OpenIdConnectConfiguration>("http://someaddress.com",
57-
new OpenIdConnectConfigurationRetriever());
58-
OpenIdConnectConfiguration config = await configManager.GetConfigurationAsync().ConfigureAwait(false);
59-
TokenValidationParameters validationParameters = new TokenValidationParameters()
55+
var configManager =
56+
new ConfigurationManager<OpenIdConnectConfiguration>(
57+
"http://someaddress.com",
58+
new OpenIdConnectConfigurationRetriever());
59+
60+
var config = await configManager.GetConfigurationAsync().ConfigureAwait(false);
61+
var validationParameters = new TokenValidationParameters()
6062
{
6163
6264
IssuerSigningKeys = config.SigningKeys;
6365
6466
}
6567

66-
JsonWebTokenHandler tokenHandler = new JsonWebTokenHandler();
68+
var tokenHandler = new JsonWebTokenHandler();
6769
result = Handler.ValidateToken(jwtToken, validationParameters);
6870
if (result.Exception != null && result.Exception is SecurityTokenSignatureKeyNotFoundException)
6971
{
@@ -75,11 +77,12 @@ if (result.Exception != null && result.Exception is SecurityTokenSignatureKeyNot
7577
IssuerSigningKeys = config.SigningKeys,
7678
7779
};
80+
7881
// attempt to validate token again after refresh
7982
result = Handler.ValidateToken(jwtToken, validationParameters);
8083
}
8184
```
8285

83-
## Next Steps
86+
## Next steps
8487

8588
To learn more, see [token validation in a protected web API](scenario-protected-web-api-app-configuration.md#token-validation)

0 commit comments

Comments
 (0)