forked from DotNetOpenAuth/DotNetOpenAuth
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathOAuthServiceProvider.cs
77 lines (68 loc) · 2.44 KB
/
OAuthServiceProvider.cs
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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
//-----------------------------------------------------------------------
// <copyright file="OAuthServiceProvider.cs" company="Outercurve Foundation">
// Copyright (c) Outercurve Foundation. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace RelyingPartyLogic {
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth2;
using DotNetOpenAuth.OAuth2.ChannelElements;
using DotNetOpenAuth.OAuth2.Messages;
public class OAuthServiceProvider {
private const string PendingAuthorizationRequestSessionKey = "PendingAuthorizationRequest";
/// <summary>
/// The lock to synchronize initialization of the <see cref="authorizationServer"/> field.
/// </summary>
private static readonly object InitializerLock = new object();
/// <summary>
/// The shared service description for this web site.
/// </summary>
private static AuthorizationServerDescription authorizationServerDescription;
/// <summary>
/// The shared authorization server.
/// </summary>
private static AuthorizationServer authorizationServer;
/// <summary>
/// Gets the service provider.
/// </summary>
/// <value>The service provider.</value>
public static AuthorizationServer AuthorizationServer {
get {
EnsureInitialized();
return authorizationServer;
}
}
/// <summary>
/// Gets the service description.
/// </summary>
/// <value>The service description.</value>
public static AuthorizationServerDescription AuthorizationServerDescription {
get {
EnsureInitialized();
return authorizationServerDescription;
}
}
/// <summary>
/// Initializes the <see cref="authorizationServer"/> field if it has not yet been initialized.
/// </summary>
private static void EnsureInitialized() {
if (authorizationServer == null) {
lock (InitializerLock) {
if (authorizationServerDescription == null) {
authorizationServerDescription = new AuthorizationServerDescription {
AuthorizationEndpoint = new Uri(Utilities.ApplicationRoot, "OAuth.ashx"),
TokenEndpoint = new Uri(Utilities.ApplicationRoot, "OAuth.ashx"),
};
}
if (authorizationServer == null) {
authorizationServer = new AuthorizationServer(new OAuthAuthorizationServer());
}
}
}
}
}
}