1
/* Copyright (c) 2006 Google Inc.
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
15
#region Using directives
22
using System.Security.Cryptography;
26
/////////////////////////////////////////////////////////////////////
27
// <summary>contains AuthSub request helper classes
29
////////////////////////////////////////////////////////////////////
30
namespace Google.GData.Client
32
//////////////////////////////////////////////////////////////////////
33
/// <summary> GDataAuthSubRequestFactory implementation</summary>
34
//////////////////////////////////////////////////////////////////////
35
public class GAuthSubRequestFactory : GDataGAuthRequestFactory
38
/// holds the private key that is used to sign the requests
39
private AsymmetricAlgorithm privateKey;
41
//////////////////////////////////////////////////////////////////////
42
/// <summary>default constructor</summary>
43
//////////////////////////////////////////////////////////////////////
44
public GAuthSubRequestFactory(string service, string applicationName) : base(service, applicationName)
47
/////////////////////////////////////////////////////////////////////////////
50
//////////////////////////////////////////////////////////////////////
51
/// <summary>default constructor</summary>
52
//////////////////////////////////////////////////////////////////////
53
public override IGDataRequest CreateRequest(GDataRequestType type, Uri uriTarget)
55
return new GAuthSubRequest(type, uriTarget, this);
57
/////////////////////////////////////////////////////////////////////////////
59
//////////////////////////////////////////////////////////////////////
60
/// <summary>accessor method public string Token</summary>
61
/// <returns>the string token for the authsub request </returns>
62
//////////////////////////////////////////////////////////////////////
65
get {return this.GAuthToken;}
66
set {this.GAuthToken = value;}
68
// end of accessor public string Token
70
//////////////////////////////////////////////////////////////////////
71
/// <summary>accessor method public AsymmetricAlgorithm PrivateKey</summary>
72
/// <returns>the private Key used for the authsub request </returns>
73
//////////////////////////////////////////////////////////////////////
74
public AsymmetricAlgorithm PrivateKey
76
get {return this.privateKey;}
77
set {this.privateKey = value;}
79
// end of accessor public string Token
84
/////////////////////////////////////////////////////////////////////////////
87
//////////////////////////////////////////////////////////////////////
88
/// <summary>base GDataRequest implementation</summary>
89
//////////////////////////////////////////////////////////////////////
90
public class GAuthSubRequest : GDataGAuthRequest
92
/// <summary>holds the factory instance</summary>
93
private GAuthSubRequestFactory factory;
96
//////////////////////////////////////////////////////////////////////
97
/// <summary>default constructor</summary>
98
//////////////////////////////////////////////////////////////////////
99
internal GAuthSubRequest(GDataRequestType type, Uri uriTarget, GAuthSubRequestFactory factory) :
100
base(type, uriTarget, factory)
102
this.factory = factory;
104
/////////////////////////////////////////////////////////////////////////////
106
//////////////////////////////////////////////////////////////////////
107
/// <summary>sets up the correct credentials for this call, pending
108
/// security scheme</summary>
109
//////////////////////////////////////////////////////////////////////
110
protected override void EnsureCredentials()
112
HttpWebRequest http = this.Request as HttpWebRequest;
114
string header = AuthSubUtil.formAuthorizationHeader(this.factory.Token,
115
this.factory.PrivateKey,
118
this.Request.Headers.Add(header);
120
/////////////////////////////////////////////////////////////////////////////
122
/////////////////////////////////////////////////////////////////////////////
124
/////////////////////////////////////////////////////////////////////////////