|
4 | 4 | using System.Security.Claims;
|
5 | 5 | using System.Threading.Tasks;
|
6 | 6 | using Microsoft.AspNetCore.Http;
|
7 |
| -using Microsoft.Extensions.DependencyInjection; |
8 | 7 |
|
9 | 8 | namespace Microsoft.AspNetCore.Authentication
|
10 | 9 | {
|
| 10 | + /// <summary> |
| 11 | + /// Extension methods to expose Authentication on HttpContext. |
| 12 | + /// </summary> |
11 | 13 | public static class AuthenticationHttpContextExtensions
|
12 | 14 | {
|
| 15 | + /// <summary> |
| 16 | + /// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultAuthenticationScheme"/> scheme. |
| 17 | + /// </summary> |
| 18 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 19 | + /// <returns>The <see cref="AuthenticateResult"/>.</returns> |
13 | 20 | public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context) =>
|
14 | 21 | context.AuthenticateAsync(scheme: null);
|
15 | 22 |
|
| 23 | + /// <summary> |
| 24 | + /// Extension method for authenticate. |
| 25 | + /// </summary> |
| 26 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 27 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 28 | + /// <returns>The <see cref="AuthenticateResult"/>.</returns> |
16 | 29 | public static Task<AuthenticateResult> AuthenticateAsync(this HttpContext context, string scheme) =>
|
17 | 30 | context.RequestServices.GetRequiredService<IAuthenticationService>().AuthenticateAsync(context, scheme);
|
18 | 31 |
|
| 32 | + /// <summary> |
| 33 | + /// Extension method for Challenge. |
| 34 | + /// </summary> |
| 35 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 36 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 37 | + /// <returns>The result.</returns> |
19 | 38 | public static Task ChallengeAsync(this HttpContext context, string scheme) =>
|
20 | 39 | context.ChallengeAsync(scheme, properties: null);
|
21 | 40 |
|
| 41 | + /// <summary> |
| 42 | + /// Extension method for authenticate using the <see cref="AuthenticationOptions.DefaultChallengeScheme"/> scheme. |
| 43 | + /// </summary> |
| 44 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 45 | + /// <returns>The task.</returns> |
22 | 46 | public static Task ChallengeAsync(this HttpContext context) =>
|
23 | 47 | context.ChallengeAsync(scheme: null, properties: null);
|
24 | 48 |
|
| 49 | + /// <summary> |
| 50 | + /// Extension method for Challenge. |
| 51 | + /// </summary> |
| 52 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 53 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 54 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 55 | + /// <returns>The task.</returns> |
25 | 56 | public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
|
26 | 57 | context.ChallengeAsync(scheme, properties: properties, behavior: ChallengeBehavior.Automatic);
|
27 | 58 |
|
| 59 | + /// <summary> |
| 60 | + /// Extension method for Challenge. |
| 61 | + /// </summary> |
| 62 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 63 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 64 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 65 | + /// <param name="behavior">The <see cref="ChallengeBehavior"/> behavior.</param> |
| 66 | + /// <returns>The task.</returns> |
28 | 67 | public static Task ChallengeAsync(this HttpContext context, string scheme, AuthenticationProperties properties, ChallengeBehavior behavior) =>
|
29 | 68 | context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties, behavior);
|
30 | 69 |
|
| 70 | + /// <summary> |
| 71 | + /// Extension method for Forbid. |
| 72 | + /// </summary> |
| 73 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 74 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 75 | + /// <returns>The task.</returns> |
31 | 76 | public static Task ForbidAsync(this HttpContext context, string scheme) =>
|
32 | 77 | context.ForbidAsync(scheme, properties: null);
|
33 | 78 |
|
| 79 | + /// <summary> |
| 80 | + /// Extension method for Forbid. |
| 81 | + /// </summary> |
| 82 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 83 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 84 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 85 | + /// <returns>The task.</returns> |
34 | 86 | public static Task ForbidAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
|
35 | 87 | context.RequestServices.GetRequiredService<IAuthenticationService>().ChallengeAsync(context, scheme, properties, ChallengeBehavior.Forbidden);
|
36 | 88 |
|
| 89 | + /// <summary> |
| 90 | + /// Extension method for SignIn. |
| 91 | + /// </summary> |
| 92 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 93 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 94 | + /// <param name="principal">The user.</param> |
| 95 | + /// <returns>The task.</returns> |
37 | 96 | public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal) =>
|
38 | 97 | context.SignInAsync(scheme, principal, properties: null);
|
39 | 98 |
|
| 99 | + /// <summary> |
| 100 | + /// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>. |
| 101 | + /// </summary> |
| 102 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 103 | + /// <param name="principal">The user.</param> |
| 104 | + /// <returns>The task.</returns> |
40 | 105 | public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal) =>
|
41 | 106 | context.SignInAsync(scheme: null, principal: principal, properties: null);
|
42 | 107 |
|
| 108 | + /// <summary> |
| 109 | + /// Extension method for SignIn using the <see cref="AuthenticationOptions.DefaultSignInScheme"/>. |
| 110 | + /// </summary> |
| 111 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 112 | + /// <param name="principal">The user.</param> |
| 113 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 114 | + /// <returns>The task.</returns> |
43 | 115 | public static Task SignInAsync(this HttpContext context, ClaimsPrincipal principal, AuthenticationProperties properties) =>
|
44 | 116 | context.SignInAsync(scheme: null, principal: principal, properties: properties);
|
45 | 117 |
|
| 118 | + /// <summary> |
| 119 | + /// Extension method for SignIn. |
| 120 | + /// </summary> |
| 121 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 122 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 123 | + /// <param name="principal">The user.</param> |
| 124 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 125 | + /// <returns>The task.</returns> |
46 | 126 | public static Task SignInAsync(this HttpContext context, string scheme, ClaimsPrincipal principal, AuthenticationProperties properties) =>
|
47 | 127 | context.RequestServices.GetRequiredService<IAuthenticationService>().SignInAsync(context, scheme, principal, properties);
|
48 | 128 |
|
49 |
| - |
| 129 | + /// <summary> |
| 130 | + /// Extension method for SignOut. |
| 131 | + /// </summary> |
| 132 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 133 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 134 | + /// <returns>The task.</returns> |
50 | 135 | public static Task SignOutAsync(this HttpContext context, string scheme) => context.SignOutAsync(scheme, properties: null);
|
51 | 136 |
|
| 137 | + /// <summary> |
| 138 | + /// Extension method for SignOut. |
| 139 | + /// </summary> |
| 140 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 141 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 142 | + /// <param name="properties">The <see cref="AuthenticationProperties"/> properties.</param> |
| 143 | + /// <returns></returns> |
52 | 144 | public static Task SignOutAsync(this HttpContext context, string scheme, AuthenticationProperties properties) =>
|
53 | 145 | context.RequestServices.GetRequiredService<IAuthenticationService>().SignOutAsync(context, scheme, properties);
|
54 | 146 |
|
55 |
| - public static Task<string> GetTokenAsync(this HttpContext context, string signInScheme, string tokenName) => |
56 |
| - context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, signInScheme, tokenName); |
| 147 | + /// <summary> |
| 148 | + /// Extension method for getting the value of an authentication token. |
| 149 | + /// </summary> |
| 150 | + /// <param name="context">The <see cref="HttpContext"/> context.</param> |
| 151 | + /// <param name="scheme">The name of the authentication scheme.</param> |
| 152 | + /// <param name="tokenName">The name of the token.</param> |
| 153 | + /// <returns>The value of the token.</returns> |
| 154 | + public static Task<string> GetTokenAsync(this HttpContext context, string scheme, string tokenName) => |
| 155 | + context.RequestServices.GetRequiredService<IAuthenticationService>().GetTokenAsync(context, scheme, tokenName); |
57 | 156 | }
|
58 | 157 | }
|
0 commit comments