1
1
/*
2
2
* Licensed under the Apache License, Version 2.0 (http://www.apache.org/licenses/LICENSE-2.0)
3
- * See https://github .com/aspnet-contrib/AspNet.Security.OAuth.Providers
3
+ * See https://VisualStudio .com/aspnet-contrib/AspNet.Security.OAuth.Providers
4
4
* for more information concerning the license and the contributors participating to this project.
5
5
*/
6
6
7
7
using System ;
8
8
using AspNet . Security . OAuth . VisualStudio ;
9
9
using JetBrains . Annotations ;
10
- using Microsoft . Extensions . Options ;
10
+ using Microsoft . AspNetCore . Authentication ;
11
11
12
- namespace Microsoft . AspNetCore . Builder
12
+ namespace Microsoft . Extensions . DependencyInjection
13
13
{
14
14
/// <summary>
15
- /// Extension methods to add VisualStudio authentication capabilities to an HTTP application pipeline.
15
+ /// Extension methods to add authentication capabilities to an HTTP application pipeline.
16
16
/// </summary>
17
17
public static class VisualStudioAuthenticationExtensions
18
18
{
19
19
/// <summary>
20
- /// Adds the <see cref="VisualStudioAuthenticationMiddleware "/> middleware to the specified
21
- /// <see cref="IApplicationBuilder "/>, which enables VisualStudio authentication capabilities.
20
+ /// Adds <see cref="VisualStudioAuthenticationHandler "/> to the specified
21
+ /// <see cref="AuthenticationBuilder "/>, which enables VisualStudio authentication capabilities.
22
22
/// </summary>
23
- /// <param name="app">The <see cref="IApplicationBuilder"/> to add the middleware to.</param>
24
- /// <param name="options">A <see cref="VisualStudioAuthenticationOptions"/> that specifies options for the middleware.</param>
25
- /// <returns>A reference to this instance after the operation has completed.</returns>
26
- public static IApplicationBuilder UseVisualStudioAuthentication (
27
- [ NotNull ] this IApplicationBuilder app ,
28
- [ NotNull ] VisualStudioAuthenticationOptions options )
23
+ /// <param name="builder">The authentication builder.</param>
24
+ /// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
25
+ public static AuthenticationBuilder AddVisualStudio ( [ NotNull ] this AuthenticationBuilder builder )
29
26
{
30
- if ( app == null )
31
- {
32
- throw new ArgumentNullException ( nameof ( app ) ) ;
33
- }
34
-
35
- if ( options == null )
36
- {
37
- throw new ArgumentNullException ( nameof ( options ) ) ;
38
- }
39
-
40
- return app . UseMiddleware < VisualStudioAuthenticationMiddleware > ( Options . Create ( options ) ) ;
27
+ return builder . AddVisualStudio ( VisualStudioAuthenticationDefaults . AuthenticationScheme , options => { } ) ;
41
28
}
42
29
43
30
/// <summary>
44
- /// Adds the <see cref="VisualStudioAuthenticationMiddleware "/> middleware to the specified
45
- /// <see cref="IApplicationBuilder "/>, which enables VisualStudio authentication capabilities.
31
+ /// Adds <see cref="VisualStudioAuthenticationHandler "/> to the specified
32
+ /// <see cref="AuthenticationBuilder "/>, which enables VisualStudio authentication capabilities.
46
33
/// </summary>
47
- /// <param name="app ">The <see cref="IApplicationBuilder"/> to add the middleware to .</param>
48
- /// <param name="configuration">An action delegate to configure the provided <see cref="VisualStudioAuthenticationOptions"/> .</param>
49
- /// <returns>A reference to this instance after the operation has completed .</returns>
50
- public static IApplicationBuilder UseVisualStudioAuthentication (
51
- [ NotNull ] this IApplicationBuilder app ,
34
+ /// <param name="builder ">The authentication builder .</param>
35
+ /// <param name="configuration">The delegate used to configure the OpenID 2.0 options .</param>
36
+ /// <returns>The <see cref="AuthenticationBuilder"/> .</returns>
37
+ public static AuthenticationBuilder AddVisualStudio (
38
+ [ NotNull ] this AuthenticationBuilder builder ,
52
39
[ NotNull ] Action < VisualStudioAuthenticationOptions > configuration )
53
40
{
54
- if ( app == null )
55
- {
56
- throw new ArgumentNullException ( nameof ( app ) ) ;
57
- }
58
-
59
- if ( configuration == null )
60
- {
61
- throw new ArgumentNullException ( nameof ( configuration ) ) ;
62
- }
41
+ return builder . AddVisualStudio ( VisualStudioAuthenticationDefaults . AuthenticationScheme , configuration ) ;
42
+ }
63
43
64
- var options = new VisualStudioAuthenticationOptions ( ) ;
65
- configuration ( options ) ;
44
+ /// <summary>
45
+ /// Adds <see cref="VisualStudioAuthenticationHandler"/> to the specified
46
+ /// <see cref="AuthenticationBuilder"/>, which enables VisualStudio authentication capabilities.
47
+ /// </summary>
48
+ /// <param name="builder">The authentication builder.</param>
49
+ /// <param name="scheme">The authentication scheme associated with this instance.</param>
50
+ /// <param name="configuration">The delegate used to configure the VisualStudio options.</param>
51
+ /// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
52
+ public static AuthenticationBuilder AddVisualStudio (
53
+ [ NotNull ] this AuthenticationBuilder builder , [ NotNull ] string scheme ,
54
+ [ NotNull ] Action < VisualStudioAuthenticationOptions > configuration )
55
+ {
56
+ return builder . AddVisualStudio ( scheme , VisualStudioAuthenticationDefaults . DisplayName , configuration ) ;
57
+ }
66
58
67
- return app . UseMiddleware < VisualStudioAuthenticationMiddleware > ( Options . Create ( options ) ) ;
59
+ /// <summary>
60
+ /// Adds <see cref="VisualStudioAuthenticationHandler"/> to the specified
61
+ /// <see cref="AuthenticationBuilder"/>, which enables VisualStudio authentication capabilities.
62
+ /// </summary>
63
+ /// <param name="builder">The authentication builder.</param>
64
+ /// <param name="scheme">The authentication scheme associated with this instance.</param>
65
+ /// <param name="name">The optional display name associated with this instance.</param>
66
+ /// <param name="configuration">The delegate used to configure the VisualStudio options.</param>
67
+ /// <returns>The <see cref="AuthenticationBuilder"/>.</returns>
68
+ public static AuthenticationBuilder AddVisualStudio (
69
+ [ NotNull ] this AuthenticationBuilder builder ,
70
+ [ NotNull ] string scheme , [ CanBeNull ] string name ,
71
+ [ NotNull ] Action < VisualStudioAuthenticationOptions > configuration )
72
+ {
73
+ return builder . AddOAuth < VisualStudioAuthenticationOptions , VisualStudioAuthenticationHandler > ( scheme , name , configuration ) ;
68
74
}
69
75
}
70
- }
76
+ }
0 commit comments