Skip to content

Commit 7ab874c

Browse files
authored
Updarting the ValidateIssuer snipet in README.md
1 parent 7bd53b8 commit 7ab874c

File tree

1 file changed

+25
-25
lines changed

1 file changed

+25
-25
lines changed

README.md

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -230,30 +230,30 @@ The code of the overloaded `Configure` method is also modified to accept tokens
230230
/// <returns>The <c>issuer</c> if it's valid, or otherwise <c>null</c></returns>
231231
private string ValidateIssuer(string issuer, SecurityToken securityToken, TokenValidationParameters validationParameters)
232232
{
233-
Uri uri = new Uri(issuer);
234-
Uri authorityUri = new Uri(_azureOptions.Instance);
235-
string[] parts = uri.AbsolutePath.Split('/');
236-
if (parts.Length >= 2)
237-
{
238-
Guid tenantId;
239-
if (uri.Scheme != authorityUri.Scheme || uri.Authority != authorityUri.Authority)
240-
{
241-
return null;
242-
}
243-
if (!Guid.TryParse(parts[1], out tenantId))
244-
{
245-
return null;
246-
}
247-
if (parts.Length> 2 && parts[2] != "v2.0")
248-
{
249-
return null;
250-
}
251-
return issuer;
252-
}
253-
else
254-
{
255-
return null;
256-
}
233+
Uri uri = new Uri(issuer);
234+
Uri authorityUri = new Uri(_azureOptions.Instance);
235+
string[] parts = uri.AbsolutePath.Split('/');
236+
if (parts.Length >= 2)
237+
{
238+
Guid tenantId;
239+
if (uri.Scheme != authorityUri.Scheme || uri.Authority != authorityUri.Authority)
240+
{
241+
throw new SecurityTokenInvalidIssuerException("Issuer has wrong authority");
242+
}
243+
if (!Guid.TryParse(parts[1], out tenantId))
244+
{
245+
throw new SecurityTokenInvalidIssuerException("Cannot find the tenant GUID for the issuer");
246+
}
247+
if (parts.Length> 2 && parts[2] != "v2.0")
248+
{
249+
throw new SecurityTokenInvalidIssuerException("Only accepted protocol versions are AAD v1.0 or V2.0");
250+
}
251+
return issuer;
252+
}
253+
else
254+
{
255+
throw new SecurityTokenInvalidIssuerException("Unknown issuer");
256+
}
257257
}
258258

259259
public void Configure(string name, JwtBearerOptions options)
@@ -341,4 +341,4 @@ For more information, visit the following links:
341341

342342
- [Introduction to Identity on ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/identity?view=aspnetcore-2.1&tabs=visual-studio%2Caspnetcore2x)
343343
- [AuthenticationBuilder](https://docs.microsoft.com/en-us/dotnet/api/microsoft.aspnetcore.authentication.authenticationbuilder?view=aspnetcore-2.0)
344-
- [Azure Active Directory with ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/azure-active-directory/?view=aspnetcore-2.1)
344+
- [Azure Active Directory with ASP.NET Core](https://docs.microsoft.com/en-us/aspnet/core/security/authentication/azure-active-directory/?view=aspnetcore-2.1)

0 commit comments

Comments
 (0)