@@ -60,19 +60,21 @@ public static bool IsAuthDisabled(this HttpRequestMessage request)
60
60
/// the specified level.
61
61
/// </summary>
62
62
/// <param name="request">The request.</param>
63
- /// <param name="level ">The level to check.</param>
63
+ /// <param name="levelToCheck ">The level to check.</param>
64
64
/// <param name="keyName">Optional key name if key based auth is being used</param>
65
65
/// <returns>True if the request is authorized at the specified level,
66
66
/// false otherwise.</returns>
67
- public static bool HasAuthorizationLevel ( this HttpRequestMessage request , AuthorizationLevel level , string keyName = null )
67
+ public static bool HasAuthorizationLevel ( this HttpRequestMessage request , AuthorizationLevel levelToCheck , string keyName = null )
68
68
{
69
- if ( request . IsAuthDisabled ( ) )
69
+ if ( request . IsAuthDisabled ( ) || levelToCheck == AuthorizationLevel . Anonymous )
70
70
{
71
+ // when auth is disabled or the required level is Anonymous
72
+ // the request is authorized
71
73
return true ;
72
74
}
73
75
74
- var authorizationLevel = request . GetAuthorizationLevel ( ) ;
75
- if ( authorizationLevel == AuthorizationLevel . Admin )
76
+ var requestAuthorizationLevel = request . GetAuthorizationLevel ( ) ;
77
+ if ( requestAuthorizationLevel == AuthorizationLevel . Admin )
76
78
{
77
79
// requests authorized at admin level are always allowed
78
80
return true ;
@@ -89,7 +91,7 @@ public static bool HasAuthorizationLevel(this HttpRequestMessage request, Author
89
91
}
90
92
91
93
// otherwise, the request level must exactly match the required level
92
- return authorizationLevel == level ;
94
+ return requestAuthorizationLevel == levelToCheck ;
93
95
}
94
96
95
97
public static string GetHeaderValueOrDefault ( this HttpRequestMessage request , string headerName )
0 commit comments