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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
|
//-----------------------------------------------------------------------
// <copyright file="DotNetOpenAuthWebConsumer.cs" company="Microsoft">
// Copyright (c) Microsoft. All rights reserved.
// </copyright>
//-----------------------------------------------------------------------
namespace DotNetOpenAuth.AspNet.Clients {
using System;
using System.Collections.Generic;
using System.Net;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;
/// <summary>
/// The dot net open auth web consumer.
/// </summary>
public class DotNetOpenAuthWebConsumer : IOAuthWebWorker, IDisposable {
#region Constants and Fields
/// <summary>
/// The _web consumer.
/// </summary>
private readonly WebConsumer webConsumer;
#endregion
#region Constructors and Destructors
/// <summary>
/// Initializes a new instance of the <see cref="DotNetOpenAuthWebConsumer"/> class.
/// </summary>
/// <param name="serviceDescription">
/// The service description.
/// </param>
/// <param name="tokenManager">
/// The token manager.
/// </param>
public DotNetOpenAuthWebConsumer(ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager) {
Requires.NotNull(serviceDescription, "serviceDescription");
Requires.NotNull(tokenManager, "tokenManager");
this.webConsumer = new WebConsumer(serviceDescription, tokenManager);
}
#endregion
#region Public Methods and Operators
/// <summary>
/// The prepare authorized request.
/// </summary>
/// <param name="profileEndpoint">
/// The profile endpoint.
/// </param>
/// <param name="accessToken">
/// The access token.
/// </param>
/// <returns>An HTTP request.</returns>
public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint profileEndpoint, string accessToken) {
return this.webConsumer.PrepareAuthorizedRequest(profileEndpoint, accessToken);
}
/// <summary>
/// The process user authorization.
/// </summary>
/// <returns>The response message.</returns>
public AuthorizedTokenResponse ProcessUserAuthorization() {
return this.webConsumer.ProcessUserAuthorization();
}
/// <summary>
/// The request authentication.
/// </summary>
/// <param name="callback">
/// The callback.
/// </param>
public void RequestAuthentication(Uri callback) {
var redirectParameters = new Dictionary<string, string>();
UserAuthorizationRequest request = this.webConsumer.PrepareRequestUserAuthorization(
callback, null, redirectParameters);
this.webConsumer.Channel.PrepareResponse(request).Send();
}
#endregion
#region IDisposable members
/// <summary>
/// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
/// </summary>
/// <filterpriority>2</filterpriority>
public void Dispose() {
this.Dispose(true);
GC.SuppressFinalize(this);
}
#endregion
/// <summary>
/// Releases unmanaged and - optionally - managed resources
/// </summary>
/// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
protected virtual void Dispose(bool disposing) {
if (disposing) {
this.webConsumer.Dispose();
}
}
}
}
|