Repository navigation
Expand file tree
/
Copy pathOAuthExtensions.cs
More file actions
61 lines (54 loc) · 2.18 KB
/
Copy pathOAuthExtensions.cs
File metadata and controls
61 lines (54 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
// Copyright (c) .NET Foundation. All rights reserved.
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using System;
using Microsoft.AspNet.Authentication.OAuth;
namespace Microsoft.AspNet.Builder
{
/// <summary>
/// Extension methods for using <see cref="OAuthMiddleware"/>
/// </summary>
public static class OAuthExtensions
{
/// <summary>
/// Authenticate users using OAuth.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param>
/// <param name="configureOptions">Configures the middleware options.</param>
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
public static IApplicationBuilder UseOAuthAuthentication(this IApplicationBuilder app, Action<OAuthOptions> configureOptions)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (configureOptions == null)
{
throw new ArgumentNullException(nameof(configureOptions));
}
var options = new OAuthOptions();
if (configureOptions != null)
{
configureOptions(options);
}
return app.UseOAuthAuthentication(options);
}
/// <summary>
/// Authenticate users using OAuth.
/// </summary>
/// <param name="app">The <see cref="IApplicationBuilder"/> passed to the configure method.</param>
/// <param name="options">The middleware configuration options.</param>
/// <returns>The updated <see cref="IApplicationBuilder"/>.</returns>
public static IApplicationBuilder UseOAuthAuthentication(this IApplicationBuilder app, OAuthOptions options)
{
if (app == null)
{
throw new ArgumentNullException(nameof(app));
}
if (options == null)
{
throw new ArgumentNullException(nameof(options));
}
return app.UseMiddleware<OAuthMiddleware<OAuthOptions>>(options);
}
}
}