summaryrefslogtreecommitdiffstats
path: root/src/DotNetOpenAuth.Web/Clients/OAuth/DotNetOpenAuthWebConsumer.cs
blob: b66f0b1c7d0dc1ab1f15bfbe3673205bb4dc90a3 (plain)
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
using System;
using System.Collections.Generic;
using System.Net;
using DotNetOpenAuth.Messaging;
using DotNetOpenAuth.OAuth;
using DotNetOpenAuth.OAuth.ChannelElements;
using DotNetOpenAuth.OAuth.Messages;

namespace DotNetOpenAuth.Web.Clients
{
    public class DotNetOpenAuthWebConsumer : IOAuthWebWorker
    {
        private readonly WebConsumer _webConsumer;

        public DotNetOpenAuthWebConsumer(ServiceProviderDescription serviceDescription, IConsumerTokenManager tokenManager)
        {
            if (serviceDescription == null)
            {
                throw new ArgumentNullException("consumer");
            }

            if (tokenManager == null)
            {
                throw new ArgumentNullException("tokenManager");
            }

            _webConsumer = new WebConsumer(serviceDescription, tokenManager);
        }

        public void RequestAuthentication(Uri callback)
        {
            var redirectParameters = new Dictionary<string, string>() { { "force_login", "false" } };
            UserAuthorizationRequest request = _webConsumer.PrepareRequestUserAuthorization(callback, null, redirectParameters);
            _webConsumer.Channel.PrepareResponse(request).Send();
        }

        public AuthorizedTokenResponse ProcessUserAuthorization()
        {
            return _webConsumer.ProcessUserAuthorization();
        }

        public HttpWebRequest PrepareAuthorizedRequest(MessageReceivingEndpoint profileEndpoint, string accessToken)
        {
            return _webConsumer.PrepareAuthorizedRequest(profileEndpoint, accessToken);
        }
    }
}