Index: Src/GoogleApis.Auth.DotNet4/GoogleApis.Auth.DotNet4.csproj
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth.DotNet4/GoogleApis.Auth.DotNet4.csproj
@@ -0,0 +1,115 @@
+
+
+
+
+ Debug
+ AnyCPU
+ {8CFBF8D2-64CB-4703-A5B0-F9EF4DE41FA7}
+ Library
+ Properties
+ Google.Apis.Auth
+ Google.Apis.Auth.PlatformServices
+ v4.0
+ 512
+ ..\..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ Google.Apis.Auth.PlatformServices.xml
+
+
+
+ ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.dll
+
+
+ ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.dll
+
+
+ ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\net40\Microsoft.Threading.Tasks.Extensions.Desktop.dll
+
+
+ ..\..\packages\Newtonsoft.Json.5.0.6\lib\net40\Newtonsoft.Json.dll
+
+
+
+
+
+ False
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.dll
+
+
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.Extensions.dll
+
+
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.Primitives.dll
+
+
+ False
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\net40\System.Net.Http.WebRequest.dll
+
+
+ ..\..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Runtime.dll
+
+
+ ..\..\packages\Microsoft.Bcl.1.0.19\lib\net40\System.Threading.Tasks.dll
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ {0aaaf32e-2bf0-49c5-bc2d-90874cfb5510}
+ GoogleApis.Auth
+
+
+ {c4da0abe-2c2e-4bb8-9881-5ff80b0c1afd}
+ GoogleApis.DotNet4
+
+
+ {826cf988-eee8-4b75-8f53-b7e851a17baa}
+ GoogleApis
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: Src/GoogleApis.Auth.DotNet4/OAuth2/LocalServerCodeReceiver.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth.DotNet4/OAuth2/LocalServerCodeReceiver.cs
@@ -0,0 +1,125 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Collections.Specialized;
+using System.Diagnostics;
+using System.IO;
+using System.Linq;
+using System.Net;
+using System.Net.Sockets;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Google.Apis.Auth.OAuth2.Requests;
+using Google.Apis.Auth.OAuth2.Responses;
+using Google.Apis.Logging;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ ///
+ /// OAuth 2.0 verification code receiver that runs a local server on a free port and waits for a call with the
+ /// authorization verification code.
+ ///
+ public class LocalServerCodeReceiver : ICodeReceiver
+ {
+ private static readonly ILogger Logger = ApplicationContext.Logger.ForType();
+
+ /// The call back format. Expects one port parameter.
+ private const string LoopbackCallback = "http://localhost:{0}/authorize/";
+
+ /// Close HTML tag to return the browser so it will close itself.
+ private const string ClosePageResponse =
+@"
+ OAuth 2.0 Authentication Token Received
+
+ Received verification code. Closing...
+
+
+";
+
+ private string redirectUri;
+ public string RedirectUri
+ {
+ get
+ {
+ if (!string.IsNullOrEmpty(redirectUri))
+ {
+ return redirectUri;
+ }
+
+ return redirectUri = string.Format(LoopbackCallback, GetRandomUnusedPort());
+ }
+ }
+
+ public async Task ReceiveCodeAsync(AuthorizationCodeRequestUrl url,
+ CancellationToken taskCancellationToken)
+ {
+ var authorizationUrl = url.Build().ToString();
+ using (var listener = new HttpListener())
+ {
+ listener.Prefixes.Add(RedirectUri);
+ try
+ {
+ listener.Start();
+
+ Logger.Debug("Open a browser with \"{0}\" URL", authorizationUrl);
+ Process.Start(authorizationUrl);
+
+ // Wait to get the authorization code response.
+ var context = await listener.GetContextAsync().ConfigureAwait(false);
+ NameValueCollection coll = context.Request.QueryString;
+
+ // Write a "close" response.
+ using (var writer = new StreamWriter(context.Response.OutputStream))
+ {
+ writer.WriteLine(ClosePageResponse);
+ writer.Flush();
+ }
+ context.Response.OutputStream.Close();
+
+ // Create a new response URL with a dictionary that contains all the response query parameters.
+ return new AuthorizationCodeResponseUrl(coll.AllKeys.ToDictionary(k => k, k => coll[k]));
+ }
+ finally
+ {
+ listener.Close();
+ }
+ }
+ }
+
+
+ /// Returns a random, unused port.
+ private static int GetRandomUnusedPort()
+ {
+ var listener = new TcpListener(IPAddress.Loopback, 0);
+ try
+ {
+ listener.Start();
+ return ((IPEndPoint)listener.LocalEndpoint).Port;
+ }
+ finally
+ {
+ listener.Stop();
+ }
+ }
+ }
+}
Index: Src/GoogleApis.Auth.DotNet4/OAuth2/PromptCodeReceiver.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth.DotNet4/OAuth2/PromptCodeReceiver.cs
@@ -0,0 +1,63 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Diagnostics;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Google.Apis.Auth.OAuth2.Requests;
+using Google.Apis.Auth.OAuth2.Responses;
+using Google.Apis.Logging;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ /// OAuth 2.0 verification code receiver that reads the authorization code from the user input.
+ public class PromptCodeReceiver : ICodeReceiver
+ {
+ private static readonly ILogger Logger = ApplicationContext.Logger.ForType();
+
+ public string RedirectUri
+ {
+ get { return GoogleAuthConsts.InstalledAppRedirectUri; }
+ }
+
+ public Task ReceiveCodeAsync(AuthorizationCodeRequestUrl url, CancellationToken taskCancellationToken)
+ {
+ var tcs = new TaskCompletionSource();
+
+ var authorizationUrl = url.Build().ToString();
+
+ Logger.Debug("Open a browser with \"{0}\" URL", authorizationUrl);
+ Process.Start(authorizationUrl);
+
+ string code = string.Empty;
+ while (string.IsNullOrEmpty(code))
+ {
+ Console.WriteLine("Please enter code: ");
+ code = Console.ReadLine();
+ }
+
+ Logger.Debug("Code is: \"{0}\"", code);
+
+ tcs.SetResult(new AuthorizationCodeResponseUrl
+ {
+ Code = code
+ });
+ return tcs.Task;
+ }
+ }
+}
Index: Src/GoogleApis.Auth.DotNet4/Properties/AssemblyInfo.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth.DotNet4/Properties/AssemblyInfo.cs
@@ -0,0 +1,40 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Reflection;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Google.Apis.Auth.PlatformServices")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Google Inc")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("Copyright © Google Inc 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+[assembly: AssemblyVersion("1.5.0.*")]
+
+// The following attributes are used to specify the signing key for the assembly,
+// if desired. See the Mono documentation for more information about signing.
+
+//[assembly: AssemblyDelaySign(false)]
+//[assembly: AssemblyKeyFile("")]
Index: Src/GoogleApis.Auth.DotNet4/packages.config
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth.DotNet4/packages.config
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: Src/GoogleApis.Auth/GoogleApis.Auth.csproj
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/GoogleApis.Auth.csproj
@@ -0,0 +1,119 @@
+
+
+
+
+ 10.0
+ Debug
+ AnyCPU
+ {0AAAF32E-2BF0-49C5-BC2D-90874CFB5510}
+ Library
+ Properties
+ Google.Apis.Auth
+ Google.Apis.Auth
+ v4.0
+ Profile88
+ 512
+ {786C830F-07A1-408B-BD7F-6EE04809D6DB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
+ ..\..\
+ true
+
+
+ true
+ full
+ false
+ bin\Debug\
+ DEBUG;TRACE
+ prompt
+ 4
+
+
+ pdbonly
+ true
+ bin\Release\
+ TRACE
+ prompt
+ 4
+ Google.Apis.Auth.xml
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.dll
+
+
+ ..\..\packages\Microsoft.Bcl.Async.1.0.16\lib\portable-net40+sl4+win8+wp71\Microsoft.Threading.Tasks.Extensions.dll
+
+
+ ..\..\packages\Newtonsoft.Json.5.0.6\lib\portable-net40+sl4+wp7+win8\Newtonsoft.Json.dll
+
+
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\portable-net40+sl4+win8+wp71\System.Net.Http.dll
+
+
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Extensions.dll
+
+
+ ..\..\packages\Microsoft.Net.Http.2.1.10\lib\portable-net40+sl4+win8+wp71\System.Net.Http.Primitives.dll
+
+
+ ..\..\packages\Microsoft.Bcl.1.0.19\lib\portable-net40+sl4+win8+wp71\System.Runtime.dll
+
+
+ ..\..\packages\Microsoft.Bcl.1.0.19\lib\portable-net40+sl4+win8+wp71\System.Threading.Tasks.dll
+
+
+
+
+ Designer
+
+
+
+
+ {826cf988-eee8-4b75-8f53-b7e851a17baa}
+ GoogleApis
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: Src/GoogleApis.Auth/GoogleJsonWebSignature.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/GoogleJsonWebSignature.cs
@@ -0,0 +1,42 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Google.Apis.Auth
+{
+ ///
+ /// Google JSON Web Signature as specified in https://developers.google.com/accounts/docs/OAuth2ServiceAccount.
+ ///
+ public class GoogleJsonWebSignature
+ {
+ // TODO(peleyal): We should provide a way to verify JWS.
+ // Take a look at: https://github.com/googleplus/gplus-verifytoken-csharp/blob/master/verifytoken.ashx.cs.
+
+ ///
+ /// The header as specified in https://developers.google.com/accounts/docs/OAuth2ServiceAccount#formingheader.
+ ///
+ public class Header : JsonWebSignature.Header
+ {
+ }
+
+ ///
+ /// The payload as specified in
+ /// https://developers.google.com/accounts/docs/OAuth2ServiceAccount#formingclaimset.
+ ///
+ public class Payload : JsonWebSignature.Payload
+ {
+ ///
+ /// a space-delimited list of the permissions the application requests or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("scope")]
+ public string Scope { get; set; }
+
+ ///
+ /// The email address of the user for which the application is requesting delegated access.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("prn")]
+ public string Prn { get; set; }
+ }
+ }
+}
Index: Src/GoogleApis.Auth/JsonWebSignature.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/JsonWebSignature.cs
@@ -0,0 +1,103 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Google.Apis.Auth
+{
+ ///
+ /// JSON Web Signature (JWS) implementation as specified in
+ /// http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11.
+ ///
+ public class JsonWebSignature
+ {
+ // TODO(peleyal): Implement some verify method:
+ // http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-08#section-7
+
+ ///
+ /// Header as specified in http://tools.ietf.org/html/draft-ietf-jose-json-web-signature-11#section-4.1.
+ ///
+ public class Header : JsonWebToken.Header
+ {
+ ///
+ /// Gets or set the algorithm header parameter that identifies the cryptographic algorithm used to secure
+ /// the JWS or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("alg")]
+ public string Algorithm { get; set; }
+
+ ///
+ /// Gets or sets the JSON Web Key URL header parameter that is an absolute URL that refers to a resource
+ /// for a set of JSON-encoded public keys, one of which corresponds to the key that was used to digitally
+ /// sign the JWS or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("jku")]
+ public string JwkUrl { get; set; }
+
+ ///
+ /// Gets or sets JSON Web Key header parameter that is a public key that corresponds to the key used to
+ /// digitally sign the JWS or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("jwk")]
+ public string Jwk { get; set; }
+
+ ///
+ /// Gets or sets key ID header parameter that is a hint indicating which specific key owned by the signer
+ /// should be used to validate the digital signature or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("kid")]
+ public string KeyId { get; set; }
+
+ ///
+ /// Gets or sets X.509 URL header parameter that is an absolute URL that refers to a resource for the X.509
+ /// public key certificate or certificate chain corresponding to the key used to digitally sign the JWS or
+ /// null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("x5u")]
+ public string X509Url { get; set; }
+
+ ///
+ /// Gets or sets X.509 certificate thumb print header parameter that provides a base64url encoded SHA-1
+ /// thumb-print (a.k.a. digest) of the DER encoding of an X.509 certificate that can be used to match the
+ /// certificate or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("x5t")]
+ public string X509Thumbprint { get; set; }
+
+ ///
+ /// Gets or sets X.509 certificate chain header parameter contains the X.509 public key certificate or
+ /// certificate chain corresponding to the key used to digitally sign the JWS or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("x5c")]
+ public string X509Certificate { get; set; }
+
+ ///
+ /// Gets or sets array listing the header parameter names that define extensions that are used in the JWS
+ /// header that MUST be understood and processed or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("crit")]
+ public IList critical { get; set; }
+ }
+
+ /// JWS Payload.
+ public class Payload : JsonWebToken.Payload
+ {
+ }
+ }
+}
Index: Src/GoogleApis.Auth/JsonWebToken.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/JsonWebToken.cs
@@ -0,0 +1,127 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Collections.Generic;
+
+namespace Google.Apis.Auth
+{
+ ///
+ /// JSON Web Token (JWT) implementation as specified in
+ /// http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-08.
+ ///
+ public class JsonWebToken
+ {
+ ///
+ /// JWT Header as specified in http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-08#section-5.
+ ///
+ public class Header
+ {
+ ///
+ /// Gets or sets type header parameter used to declare the type of this object or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("typ")]
+ public string Type { get; set; }
+
+ ///
+ /// Gets or sets content type header parameter used to declare structural information about the JWT or
+ /// null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("cty")]
+ public string ContentType { get; set; }
+ }
+
+ ///
+ /// JWT Payload as specified in http://tools.ietf.org/html/draft-ietf-oauth-json-web-token-08#section-4.1.
+ ///
+ public class Payload
+ {
+ ///
+ /// Gets or sets issuer claim that identifies the principal that issued the JWT or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("iss")]
+ public string Issuer { get; set; }
+
+ ///
+ /// Gets or sets subject claim identifying the principal that is the subject of the JWT or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("sub")]
+ public string Subject { get; set; }
+
+ ///
+ /// Gets or sets audience claim that identifies the audience that the JWT is intended for (should either be
+ /// a string or list) or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("aud")]
+ public object Audience { get; set; }
+
+ ///
+ /// Gets or sets expiration time claim that identifies the expiration time (in seconds) on or after which
+ /// the token MUST NOT be accepted for processing or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("exp")]
+ public long? ExpirationTimeSeconds { get; set; }
+
+ ///
+ /// Gets or sets not before claim that identifies the time (in seconds) before which the token MUST NOT be
+ /// accepted for processing or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("nbf")]
+ public long? NotBeforeTimeSeconds { get; set; }
+
+ ///
+ /// Gets or sets issued at claim that identifies the time (in seconds) at which the JWT was issued or
+ /// null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("iat")]
+ public long? IssuedAtTimeSeconds { get; set; }
+
+ ///
+ /// Gets or sets JWT ID claim that provides a unique identifier for the JWT or null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("jti")]
+ public string JwtId { get; set; }
+
+ ///
+ /// Gets or sets type claim that is used to declare a type for the contents of this JWT Claims Set or
+ /// null.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("typ")]
+ public string Type { get; set; }
+
+ /// Gets the audience property as a list.
+ [Newtonsoft.Json.JsonIgnoreAttribute]
+ public IEnumerable AudienceAsList
+ {
+ get
+ {
+ var asList = Audience as List;
+ if (asList != null)
+ {
+ return asList;
+ }
+ var list = new List();
+ var asString = Audience as string;
+ if (asString != null)
+ {
+ list.Add(asString);
+ }
+
+ return list;
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/BearerToken.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/BearerToken.cs
@@ -0,0 +1,90 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0(the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Net.Http;
+using System.Net.Http.Headers;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ ///
+ /// OAuth 2.0 helper for accessing protected resources using the Bearer token as specified in
+ /// http://tools.ietf.org/html/rfc6750.
+ ///
+ public class BearerToken
+ {
+ ///
+ /// Thread-safe OAuth 2.0 method for accessing protected resources using the Authorization header as specified
+ /// in http://tools.ietf.org/html/rfc6750#section-2.1.
+ ///
+ public class AuthorizationHeaderAccessMethod : IAccessMethod
+ {
+ const string Schema = "Bearer";
+
+ public void Intercept(HttpRequestMessage request, string accessToken)
+ {
+ request.Headers.Authorization = new AuthenticationHeaderValue(Schema, accessToken);
+ }
+
+ public string GetAccessToken(HttpRequestMessage request)
+ {
+ if (request.Headers.Authorization != null && request.Headers.Authorization.Scheme == Schema)
+ {
+ return request.Headers.Authorization.Parameter;
+ }
+ return null;
+ }
+ }
+
+ ///
+ /// Thread-safe OAuth 2.0 method for accessing protected resources using an access_token query parameter
+ /// as specified in http://tools.ietf.org/html/rfc6750#section-2.3.
+ ///
+ public class QueryParameterAccessMethod : IAccessMethod
+ {
+ const string AccessTokenKey = "access_token";
+
+ public void Intercept(HttpRequestMessage request, string accessToken)
+ {
+ var uri = request.RequestUri;
+ request.RequestUri = new Uri(string.Format("{0}&{1}{2}{3}",
+ uri.ToString(), AccessTokenKey, string.IsNullOrEmpty(uri.Query) ? "?" : "&",
+ Uri.EscapeDataString(accessToken)));
+ }
+
+ public string GetAccessToken(HttpRequestMessage request)
+ {
+ var query = request.RequestUri.Query;
+ if (string.IsNullOrEmpty(query))
+ {
+ return null;
+ }
+
+ // Remove the '?'.
+ query = query.Substring(1);
+ foreach (var parameter in query.Split('&'))
+ {
+ var keyValue = parameter.Split('=');
+ if (keyValue[0].Equals(AccessTokenKey))
+ {
+ return keyValue[1];
+ }
+ }
+ return null;
+ }
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/ClientSecrets.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/ClientSecrets.cs
@@ -0,0 +1,30 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+namespace Google.Apis.Auth.OAuth2
+{
+ /// Client credential details for installed and web applications.
+ public sealed class ClientSecrets
+ {
+ /// Gets or sets the client identifier.
+ [Newtonsoft.Json.JsonProperty("client_id")]
+ public string ClientId { get; set; }
+
+ /// Gets or sets the client Secret.
+ [Newtonsoft.Json.JsonProperty("client_secret")]
+ public string ClientSecret { get; set; }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/GoogleClientSecrets.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/GoogleClientSecrets.cs
@@ -0,0 +1,58 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+
+using Google.Apis.Json;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ ///
+ /// OAuth 2.0 client secrets model as specified in https://cloud.google.com/console/.
+ ///
+ public sealed class GoogleClientSecrets
+ {
+ /// Gets or sets the details for installed applications.
+ [Newtonsoft.Json.JsonProperty("installed")]
+ private ClientSecrets Installed { get; set; }
+
+ /// Gets or sets the details for web applications.
+ [Newtonsoft.Json.JsonProperty("web")]
+ private ClientSecrets Web { get; set; }
+
+ /// Gets the client secrets which contains the client identifier and client secret.
+ public ClientSecrets Secrets
+ {
+ get
+ {
+ if (Installed == null && Web == null)
+ {
+ throw new InvalidOperationException(
+ "At least one client secrets (Installed or Web) should be set");
+ }
+ return Installed ?? Web;
+ }
+ }
+
+ /// Loads the Google client secret from the input stream.
+ public static GoogleClientSecrets Load(Stream stream)
+ {
+ return NewtonsoftJsonSerializer.Instance.Deserialize(stream);
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/GoogleConsts.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/GoogleConsts.cs
@@ -0,0 +1,37 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+namespace Google.Apis.Auth.OAuth2
+{
+ /// Google OAuth2 constants.
+ public static class GoogleAuthConsts
+ {
+ /// The authorization code server URL.
+ public const string AuthorizationUrl = "https://accounts.google.com/o/oauth2/auth";
+
+ /// The approval URL (used in the WinRT solution as a callback).
+ public const string ApprovalUrl = "https://accounts.google.com/o/oauth2/approval";
+
+ /// The authorization token server URL
+ public const string TokenUrl = "https://accounts.google.com/o/oauth2/token";
+
+ /// Installed application redirect URI.
+ public const string InstalledAppRedirectUri = "urn:ietf:wg:oauth:2.0:oob";
+
+ /// Installed application localhost redirect URI.
+ public const string LocalhostRedirectUri = "http://localhost";
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/IAccessMethod.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/IAccessMethod.cs
@@ -0,0 +1,25 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Net.Http;
+using System.Text;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ ///
+ /// Method of presenting the access token to the resource server as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-7
+ ///
+ public interface IAccessMethod
+ {
+ ///
+ /// Intercepts a HTTP request right before the HTTP request executes by providing the access token.
+ ///
+ void Intercept(HttpRequestMessage request, string accessToken);
+
+ ///
+ /// Retrieve the original access token in the HTTP request, as provided in the method.
+ ///
+ string GetAccessToken(HttpRequestMessage request);
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/IAuthorizationCodeFlow.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/IAuthorizationCodeFlow.cs
@@ -0,0 +1,70 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Threading;
+using System.Threading.Tasks;
+
+using Google.Apis.Auth.OAuth2.Responses;
+using Google.Apis.Auth.OAuth2.Requests;
+using Google.Apis.Util;
+using Google.Apis.Util.Store;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ /// OAuth 2.0 authorization code flow that manages and persists end-user credentials.
+ public interface IAuthorizationCodeFlow : IDisposable
+ {
+ /// Gets the method for presenting the access token to the resource server.
+ IAccessMethod AccessMethod { get; }
+
+ /// Gets the clock.
+ IClock Clock { get; }
+
+ /// Gets the data store used to store the credentials.
+ IDataStore DataStore { get; }
+
+ /// Loads the user's token using the flow's .
+ /// User identifier
+ /// Cancellation token to cancel operation
+ /// Token response
+ Task LoadToken(string userId, CancellationToken taskCancellationToken);
+
+ /// Deletes the user's token using the flow's .
+ /// User identifier
+ /// Cancellation token to cancel operation
+ Task DeleteToken(string userId, CancellationToken taskCancellationToken);
+
+ /// Creates an authorization code request with the specified redirect URI.
+ AuthorizationCodeRequestUrl CreateAuthorizationCodeRequest(string redirectUri);
+
+ /// Exchanges code with a token.
+ /// User identifier
+ /// Authorization code received from the authorization server
+ /// Redirect URI which is used in the token request
+ /// Cancellation token to cancel operation
+ /// Token response which contains the access token
+ Task ExchangeCodeForToken(string userId, string code, string redirectUri,
+ CancellationToken taskCancellationToken);
+
+ /// Refreshes an access token using a refresh token.
+ /// User identifier
+ /// Refresh token which is used to get a new access token
+ /// Cancellation token to cancel operation
+ /// Token response which contains the access token and the input refresh token
+ Task RefreshToken(string userId, string refreshToken, CancellationToken taskCancellationToken);
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/IAuthorizationCodeInstalledApp.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/IAuthorizationCodeInstalledApp.cs
@@ -0,0 +1,39 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Threading;
+using System.Threading.Tasks;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ ///
+ /// Authorization code flow for an installed application that persists end-user credentials.
+ ///
+ public interface IAuthorizationCodeInstalledApp
+ {
+ /// Gets the authorization code flow.
+ IAuthorizationCodeFlow Flow { get; }
+
+ /// Gets the code receiver.
+ ICodeReceiver CodeReceiver { get; }
+
+ /// Authorizes the installed application to access user's protected data.
+ /// User identifier
+ /// Cancellation token to cancel an operation
+ /// The user's credential
+ Task Authorize(string userId, CancellationToken taskCancellationToken);
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/ICodeReceiver.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/ICodeReceiver.cs
@@ -0,0 +1,38 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Threading;
+using System.Threading.Tasks;
+
+using Google.Apis.Auth.OAuth2.Requests;
+using Google.Apis.Auth.OAuth2.Responses;
+
+namespace Google.Apis.Auth.OAuth2
+{
+ /// OAuth 2.0 verification code receiver.
+ public interface ICodeReceiver
+ {
+ /// Gets the redirected URI.
+ string RedirectUri { get; }
+
+ /// Receives the authorization code.
+ /// The authorization code request URL
+ /// Cancellation token
+ /// The authorization code response
+ Task ReceiveCodeAsync(AuthorizationCodeRequestUrl url,
+ CancellationToken taskCancellationToken);
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationCodeRequestUrl.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationCodeRequestUrl.cs
@@ -0,0 +1,54 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+using Google.Apis.Requests;
+using Google.Apis.Requests.Parameters;
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// OAuth 2.0 request URL for an authorization web page to allow the end user to authorize the application to
+ /// access their protected resources and that returns an authorization code, as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-4.1.
+ ///
+ public class AuthorizationCodeRequestUrl : AuthorizationRequestUrl
+ {
+ ///
+ /// Constructs a new authorization code request with the specified URI and sets response_type to code.
+ ///
+ public AuthorizationCodeRequestUrl(Uri authorizationServerEncodedUrl)
+ : base(authorizationServerEncodedUrl)
+ {
+ ResponseType = "code";
+ }
+
+ /// Creates a which is used to request the authorization code.
+ public Uri Build()
+ {
+ var builder = new RequestBuilder()
+ {
+ BaseUri = AuthorizationServerEncodedUrl
+ };
+ ParameterUtils.InitParameters(builder, this);
+ return builder.BuildUri();
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationCodeTokenRequest.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationCodeTokenRequest.cs
@@ -0,0 +1,45 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// OAuth 2.0 request for an access token using an authorization code as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-4.1.3.
+ ///
+ public class AuthorizationCodeTokenRequest : TokenRequest
+ {
+ /// Gets or sets the authorization code received from the authorization server.
+ [Google.Apis.Util.RequestParameterAttribute("code")]
+ public string Code { get; set; }
+
+ ///
+ /// Gets or sets the redirect URI parameter matching the redirect URI parameter in the authorization request.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("redirect_uri")]
+ public string RedirectUri { get; set; }
+
+ ///
+ /// Constructs a new authorization code token request and sets grant_type to authorization_code.
+ ///
+ public AuthorizationCodeTokenRequest()
+ {
+ GrantType = "authorization_code";
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationRequestUrl.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/AuthorizationRequestUrl.cs
@@ -0,0 +1,77 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// OAuth 2.0 request URL for an authorization web page to allow the end user to authorize the application to
+ /// access their protected resources, as specified in http://tools.ietf.org/html/rfc6749#section-3.1.
+ ///
+ public class AuthorizationRequestUrl
+ {
+ ///
+ /// Gets or sets the response type which must be code for requesting an authorization code or
+ /// token for requesting an access token (implicit grant), or space separated registered extension
+ /// values. See http://tools.ietf.org/html/rfc6749#section-3.1.1 for more details
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("response_type", Google.Apis.Util.RequestParameterType.Query)]
+ public string ResponseType { get; set; }
+
+ /// Gets or sets the client identifier.
+ [Google.Apis.Util.RequestParameterAttribute("client_id", Google.Apis.Util.RequestParameterType.Query)]
+ public string ClientId { get; set; }
+
+ ///
+ /// Gets or sets the URI that the authorization server directs the resource owner's user-agent back to the
+ /// client after a successful authorization grant, as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-3.1.2 or null for none.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("redirect_uri", Google.Apis.Util.RequestParameterType.Query)]
+ public string RedirectUri { get; set; }
+
+ ///
+ /// Gets or sets space-separated list of scopes, as specified in http://tools.ietf.org/html/rfc6749#section-3.3
+ /// or null for none.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("scope", Google.Apis.Util.RequestParameterType.Query)]
+ public string Scope { get; set; }
+
+ ///
+ /// Gets or sets the state (an opaque value used by the client to maintain state between the request and
+ /// callback, as mentioned in http://tools.ietf.org/html/rfc6749#section-3.1.2.2 or null for none.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("state", Google.Apis.Util.RequestParameterType.Query)]
+ public string State { get; set; }
+
+ private readonly Uri authorizationServerEncodedUrl;
+ ///
+ /// Gets the authorization server encoded URL.
+ ///
+ public Uri AuthorizationServerEncodedUrl
+ {
+ get { return authorizationServerEncodedUrl; }
+ }
+
+ /// Constructs a new authorization request with the specified URI.
+ /// Authorization server encoded URI
+ public AuthorizationRequestUrl(Uri authorizationServerEncodedUrl)
+ {
+ this.authorizationServerEncodedUrl = authorizationServerEncodedUrl;
+ }
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/Requests/GoogleAssertionTokenRequest.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/GoogleAssertionTokenRequest.cs
@@ -0,0 +1,39 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// Service account assertion token request as specified in
+ /// https://developers.google.com/accounts/docs/OAuth2ServiceAccount#makingrequest.
+ ///
+ public class GoogleAssertionTokenRequest : TokenRequest
+ {
+ /// Gets or sets the JWT (including signature).
+ [Google.Apis.Util.RequestParameterAttribute("assertion")]
+ public string Assertion { get; set; }
+
+ ///
+ /// Constructs a new refresh code token request and sets grant_type to
+ /// urn:ietf:params:oauth:grant-type:jwt-bearer.
+ ///
+ public GoogleAssertionTokenRequest()
+ {
+ GrantType = @"urn:ietf:params:oauth:grant-type:jwt-bearer";
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Requests/GoogleAuthorizationCodeRequestUrl.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/GoogleAuthorizationCodeRequestUrl.cs
@@ -0,0 +1,61 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// Google-specific implementation of the OAuth 2.0 URL for an authorization web page to allow the end user to
+ /// authorize the application to access their protected resources and that returns an authorization code, as
+ /// specified in https://developers.google.com/accounts/docs/OAuth2WebServer.
+ ///
+ public class GoogleAuthorizationCodeRequestUrl : AuthorizationCodeRequestUrl
+ {
+ ///
+ /// Gets or sets the access type. Set online to request on-line access or offline to request
+ /// off-line access or null for the default behavior. The default value is offline.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("access_type", Google.Apis.Util.RequestParameterType.Query)]
+ public string AccessType { get; set; }
+
+ ///
+ /// Gets pr sets prompt for consent behavior auto to request auto-approval orforce to force the
+ /// approval UI to show, or null for the default behavior.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("approval_prompt", Google.Apis.Util.RequestParameterType.Query)]
+ public string ApprovalPrompt { get; set; }
+
+ ///
+ /// Gets or sets the login hint. Sets email address or sub identifier.
+ /// When your application knows which user it is trying to authenticate, it may provide this parameter as a
+ /// hint to the Authentication Server. Passing this hint will either pre-fill the email box on the sign-in form
+ /// or select the proper multi-login session, thereby simplifying the login flow.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("login_hint", Google.Apis.Util.RequestParameterType.Query)]
+ public string LoginHint { get; set; }
+
+ ///
+ /// Constructs a new authorization code request with the given authorization server URL. This constructor sets
+ /// the to offline.
+ ///
+ public GoogleAuthorizationCodeRequestUrl(Uri authorizationServerEncodedUrl)
+ : base(authorizationServerEncodedUrl)
+ {
+ AccessType = "offline";
+ }
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/Requests/RefreshTokenRequest.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/RefreshTokenRequest.cs
@@ -0,0 +1,37 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// OAuth 2.0 request to refresh an access token using a refresh token as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-6.
+ ///
+ public class RefreshTokenRequest : TokenRequest
+ {
+ /// Gets or sets the Refresh token issued to the client.
+ [Google.Apis.Util.RequestParameterAttribute("refresh_token")]
+ public string RefreshToken { get; set; }
+
+ ///
+ /// Constructs a new refresh code token request and sets grant_type to refresh_token.
+ ///
+ public RefreshTokenRequest()
+ {
+ GrantType = "refresh_token";
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Requests/TokenRequest.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Requests/TokenRequest.cs
@@ -0,0 +1,50 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace Google.Apis.Auth.OAuth2.Requests
+{
+ ///
+ /// OAuth 2.0 request for an access token as specified in http://tools.ietf.org/html/rfc6749#section-4.
+ ///
+ public class TokenRequest
+ {
+ ///
+ /// Gets or sets space-separated list of scopes as specified in http://tools.ietf.org/html/rfc6749#section-3.3.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("scope")]
+ public string Scope { get; set; }
+
+ ///
+ /// Gets or sets the Grant type. Sets authorization_code or password or client_credentials
+ /// or refresh_token or absolute URI of the extension grant type.
+ ///
+ [Google.Apis.Util.RequestParameterAttribute("grant_type")]
+ public string GrantType { get; set; }
+
+ /// Gets or sets the client Identifier.
+ [Google.Apis.Util.RequestParameterAttribute("client_id")]
+ public string ClientId { get; set; }
+
+ /// Gets or sets the client Secret.
+ [Google.Apis.Util.RequestParameterAttribute("client_secret")]
+ public string ClientSecret { get; set; }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Responses/AuthorizationCodeResponseUrl.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Responses/AuthorizationCodeResponseUrl.cs
@@ -0,0 +1,107 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+using System.Collections.Generic;
+
+namespace Google.Apis.Auth.OAuth2.Responses
+{
+ ///
+ /// Authorization Code response for the redirect URL after end user grants or denies authorization as specified
+ /// in http://tools.ietf.org/html/rfc6749#section-4.1.2.
+ ///
+ /// Check that is not null or empty to verify the end-user granted authorization.
+ ///
+ ///
+ public class AuthorizationCodeResponseUrl
+ {
+ /// Gets or sets the authorization code generated by the authorization server.
+ public string Code { get; set; }
+
+ ///
+ /// Gets or sets the state parameter matching the state parameter in the authorization request.
+ ///
+ public string State { get; set; }
+
+ ///
+ /// Gets or sets the error code (e.g. "invalid_request", "unauthorized_client", "access_denied",
+ /// "unsupported_response_type", "invalid_scope", "server_error", "temporarily_unavailable") as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-4.1.2.1.
+ ///
+ public string Error { get; set; }
+
+ ///
+ /// Gets or sets the human-readable text which provides additional information used to assist the client
+ /// developer in understanding the error occurred.
+ ///
+ public string ErrorDescription { get; set; }
+
+ ///
+ /// Gets or sets the URI identifying a human-readable web page with provides information about the error.
+ ///
+ public string ErrorUri { get; set; }
+
+ /// Constructs a new authorization code response URL from the specified dictionary.
+ public AuthorizationCodeResponseUrl(IDictionary queryString)
+ {
+ InitFromDictionary(queryString);
+ }
+
+ #region Constructs
+
+ /// Constructs a new authorization code response URL from the specified query string.
+ public AuthorizationCodeResponseUrl(string query)
+ {
+ var pairs = query.Split('&');
+ var queryString = new Dictionary();
+ foreach (var pair in pairs)
+ {
+ var keyValue = pair.Split('=');
+ queryString[keyValue[0]] = keyValue[1];
+ }
+
+ InitFromDictionary(queryString);
+ }
+
+ /// Initializes this instance from the input dictionary.
+ private void InitFromDictionary(IDictionary queryString)
+ {
+ //TODO(peleyal): improve the following code and make it a utility
+ IDictionary> setters = new Dictionary>();
+ setters["code"] = v => Code = v;
+ setters["state"] = v => State = v;
+ setters["error"] = v => Error = v;
+ setters["error_description"] = v => ErrorDescription = v;
+ setters["error_uri"] = v => ErrorUri = v;
+
+ Action setter;
+ foreach (var pair in queryString)
+ {
+ if (setters.TryGetValue(pair.Key, out setter))
+ {
+ setter(pair.Value);
+ }
+ }
+ }
+
+ /// Constructs a new empty authorization code response URL.
+ public AuthorizationCodeResponseUrl()
+ {
+ }
+
+ #endregion
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Responses/TokenErrorResponse.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Responses/TokenErrorResponse.cs
@@ -0,0 +1,63 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+namespace Google.Apis.Auth.OAuth2.Responses
+{
+ ///
+ /// OAuth 2.0 model for a unsuccessful access token response as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-5.2.
+ ///
+ public class TokenErrorResponse
+ {
+ ///
+ /// Gets or sets error code (e.g. "invalid_request", "invalid_client", "invalid_grant", "unauthorized_client",
+ /// "unsupported_grant_type", "invalid_scope") as specified in http://tools.ietf.org/html/rfc6749#section-5.2.
+ ///
+ [Newtonsoft.Json.JsonProperty("error")]
+ public string Error { get; set; }
+
+ ///
+ /// Gets or sets a human-readable text which provides additional information used to assist the client
+ /// developer in understanding the error occurred.
+ ///
+ [Newtonsoft.Json.JsonProperty("error_description")]
+ public string ErrorDescription { get; set; }
+
+ ///
+ /// Gets or sets the URI identifying a human-readable web page with provides information about the error.
+ ///
+ [Newtonsoft.Json.JsonProperty("error_uri")]
+ public string ErrorUri { get; set; }
+
+ public override string ToString()
+ {
+ return string.Format("Error:\"{0}\", Description:\"{1}\", Uri:\"{2}\"", Error, ErrorDescription, ErrorUri);
+ }
+
+ /// Constructs a new empty token error response.
+ public TokenErrorResponse()
+ {
+ }
+
+ /// Constructs a new token error response from the given authorization code response.
+ public TokenErrorResponse(AuthorizationCodeResponseUrl authorizationCode)
+ {
+ Error = authorizationCode.Error;
+ ErrorDescription = authorizationCode.ErrorDescription;
+ ErrorUri = authorizationCode.ErrorUri;
+ }
+ }
+}
Index: Src/GoogleApis.Auth/OAuth2/Responses/TokenResponse.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Responses/TokenResponse.cs
@@ -0,0 +1,93 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+
+using Google.Apis.Util;
+
+namespace Google.Apis.Auth.OAuth2.Responses
+{
+ ///
+ /// OAuth 2.0 model for a successful access token response as specified in
+ /// http://tools.ietf.org/html/rfc6749#section-5.1.
+ ///
+ public class TokenResponse
+ {
+ /// Gets or sets the access token issued by the authorization server.
+ [Newtonsoft.Json.JsonPropertyAttribute("access_token")]
+ public string AccessToken { get; set; }
+
+ ///
+ /// Gets or sets the token type as specified in http://tools.ietf.org/html/rfc6749#section-7.1.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("token_type")]
+ public string TokenType { get; set; }
+
+ /// Gets or sets the lifetime in seconds of the access token.
+ [Newtonsoft.Json.JsonPropertyAttribute("expires_in")]
+ public Nullable ExpiresInSeconds { get; set; }
+
+ ///
+ /// Gets or sets the refresh token which can be used to obtain a new access token.
+ /// For example, the value "3600" denotes that the access token will expire in one hour from the time the
+ /// response was generated.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("refresh_token")]
+ public string RefreshToken { get; set; }
+
+ ///
+ /// Gets or sets the scope of the access token as specified in http://tools.ietf.org/html/rfc6749#section-3.3.
+ ///
+ [Newtonsoft.Json.JsonPropertyAttribute("scope")]
+ public string Scope { get; set; }
+
+ /// The date and time that this token was issued.
+ /// It should be set by the CLIENT after the token was received from the server.
+ ///
+ ///
+ public DateTime Issued { get; set; }
+
+ ///
+ /// Returns true if the token is expired or it's going to be expired in the next minute.
+ ///
+ public bool IsExpired(IClock clock)
+ {
+ //TODO(peleyal): consider move it to an extension method
+ if (!ExpiresInSeconds.HasValue)
+ {
+ return true;
+ }
+
+ return Issued.AddSeconds(ExpiresInSeconds.Value + 60) <= clock.Now;
+ }
+
+ ///
+ /// Copies all properties from the other token, except the other's refresh token property in case it's null.
+ ///
+ internal void CopyFrom(TokenResponse other)
+ {
+ AccessToken = other.AccessToken;
+ TokenType = other.TokenType;
+ ExpiresInSeconds = other.ExpiresInSeconds;
+ if (other.RefreshToken != null)
+ {
+ RefreshToken = other.RefreshToken;
+ }
+ Scope = other.Scope;
+ Issued = other.Issued;
+ }
+ }
+}
\ No newline at end of file
Index: Src/GoogleApis.Auth/OAuth2/Responses/TokenResponseException.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/OAuth2/Responses/TokenResponseException.cs
@@ -0,0 +1,37 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System;
+
+namespace Google.Apis.Auth.OAuth2.Responses
+{
+ ///
+ /// Token response exception which is thrown in case of receiving a token error when an authorization code or an
+ /// access token is expected.
+ ///
+ public class TokenResponseException : Exception
+ {
+ /// The error information.
+ public TokenErrorResponse Error { get; private set; }
+
+ /// Constructs a new token response exception from the given error.
+ public TokenResponseException(TokenErrorResponse error)
+ : base(error.ToString())
+ {
+ Error = error;
+ }
+ }
+}
Index: Src/GoogleApis.Auth/Properties/AssemblyInfo.cs
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/Properties/AssemblyInfo.cs
@@ -0,0 +1,38 @@
+/*
+Copyright 2013 Google Inc
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+*/
+
+using System.Resources;
+using System.Reflection;
+using System.Runtime.CompilerServices;
+
+// General Information about an assembly is controlled through the following
+// set of attributes. Change these attribute values to modify the information
+// associated with an assembly.
+[assembly: AssemblyTitle("Google.Apis.Auth")]
+[assembly: AssemblyDescription("")]
+[assembly: AssemblyConfiguration("")]
+[assembly: AssemblyCompany("Google Inc")]
+[assembly: AssemblyProduct("")]
+[assembly: AssemblyCopyright("Copyright © Google Inc 2013")]
+[assembly: AssemblyTrademark("")]
+[assembly: AssemblyCulture("")]
+[assembly: InternalsVisibleTo("Google.Apis.Auth.Tests")]
+
+
+// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".
+// The form "{Major}.{Minor}.*" will automatically update the build and revision,
+// and "{Major}.{Minor}.{Build}.*" will update just the revision.
+[assembly: AssemblyVersion("1.5.0.*")]
Index: Src/GoogleApis.Auth/packages.config
===================================================================
new file mode 100644
--- /dev/null
+++ b/Src/GoogleApis.Auth/packages.config
@@ -0,0 +1,8 @@
+
+
+
+
+
+
+
+
\ No newline at end of file
Index: Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs
===================================================================
--- a/Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs
+++ b/Src/GoogleApis.DotNet4/Apis/Util/Store/FileDataStore.cs
@@ -21,7 +21,7 @@
using Google.Apis.Util.Store;
using Google.Apis.Json;
-namespace Google.Apis.Apis.Util.Store
+namespace Google.Apis.Util.Store
{
///
/// File data store that implements . This store creates a different file for each
Index: Src/GoogleApis/Apis/Util/Utilities.cs
===================================================================
--- a/Src/GoogleApis/Apis/Util/Utilities.cs
+++ b/Src/GoogleApis/Apis/Util/Utilities.cs
@@ -43,12 +43,14 @@
///
/// Throws an if the string is null or empty.
///
- internal static void ThrowIfNullOrEmpty(this string str, string paramName)
+ /// The original string
+ internal static string ThrowIfNullOrEmpty(this string str, string paramName)
{
if (string.IsNullOrEmpty(str))
{
throw new ArgumentException("Parameter was empty", paramName);
}
+ return str;
}
/// Returns true in case the enumerable is null or empty.
Index: Src/GoogleApis/Properties/AssemblyInfo.cs
===================================================================
--- a/Src/GoogleApis/Properties/AssemblyInfo.cs
+++ b/Src/GoogleApis/Properties/AssemblyInfo.cs
@@ -29,6 +29,7 @@
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
[assembly: InternalsVisibleTo("Google.Apis.Tests")]
+[assembly: InternalsVisibleTo("Google.Apis.Auth")]
[assembly: InternalsVisibleTo("Google.Apis.Authentication.OAuth2")]
// The assembly version has the format "{Major}.{Minor}.{Build}.{Revision}".