diff options
author | Andrew Arnott <andrewarnott@gmail.com> | 2013-05-27 09:32:17 -0700 |
---|---|---|
committer | Andrew Arnott <andrewarnott@gmail.com> | 2013-05-27 09:32:17 -0700 |
commit | 5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba (patch) | |
tree | 026bb7a58fc6b80b680f2b5be2a25ddf1efbf0f5 /samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs | |
parent | e4c746826690259eddba106e8a44d1b52b542faf (diff) | |
parent | 064220dbab72b00f23abd041bf4a30ea87a00d88 (diff) | |
download | DotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.zip DotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.tar.gz DotNetOpenAuth-5a0a8ee4c55f323a6c1fbdb619cd89b7d28a94ba.tar.bz2 |
Merge branch 'v4.3'
Conflicts:
samples/OAuthClient/Default.aspx
samples/OAuthClient/Facebook.aspx.cs
samples/OAuthClient/Web.config
samples/OAuthClient/WindowsLive.aspx.cs
samples/OAuthClient/packages.config
src/DotNetOpenAuth.Core/Messaging/OutgoingWebResponse.cs
src/DotNetOpenAuth.Core/Messaging/StandardWebRequestHandler.cs
src/DotNetOpenAuth.OAuth.Consumer/OAuth/ConsumerBase.cs
src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HmacSha1HttpMessageHandler.cs
src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1HttpMessageHandlerBase.cs
src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1PlainTextMessageHandler.cs
src/DotNetOpenAuth.OAuth.Consumer/OAuth/OAuth1RsaSha1HttpMessageHandler.cs
src/DotNetOpenAuth.OAuth2.Client/OAuth2/WebServerClient.cs
src/packages/repositories.config
src/version.txt
Diffstat (limited to 'samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs')
-rw-r--r-- | samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs | 110 |
1 files changed, 110 insertions, 0 deletions
diff --git a/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs new file mode 100644 index 0000000..1e1a486 --- /dev/null +++ b/samples/DotNetOpenAuth.ApplicationBlock/OAuth2/Google/GoogleClient.cs @@ -0,0 +1,110 @@ +//----------------------------------------------------------------------- +// <copyright file="GoogleClient.cs" company="Outercurve Foundation"> +// Copyright (c) Outercurve Foundation. All rights reserved. +// </copyright> +//----------------------------------------------------------------------- + +namespace DotNetOpenAuth.ApplicationBlock { + using System; + using System.Collections.Generic; + using System.IO; + using System.Linq; + using System.Net; + using System.Text; + using System.Web; + using DotNetOpenAuth.Messaging; + using DotNetOpenAuth.OAuth2; + + //// https://accounts.google.com/o/oauth2/auth + + public class GoogleClient : WebServerClient { + private static readonly AuthorizationServerDescription GoogleDescription = new AuthorizationServerDescription { + TokenEndpoint = new Uri("https://accounts.google.com/o/oauth2/token"), + AuthorizationEndpoint = new Uri("https://accounts.google.com/o/oauth2/auth"), + //// RevokeEndpoint = new Uri("https://accounts.google.com/o/oauth2/revoke"), + ProtocolVersion = ProtocolVersion.V20 + }; + + /// <summary> + /// Initializes a new instance of the <see cref="GoogleClient"/> class. + /// </summary> + public GoogleClient() + : base(GoogleDescription) { + } + + public IOAuth2Graph GetGraph(IAuthorizationState authState, string[] fields = null) { + if ((authState != null) && (authState.AccessToken != null)) { + WebRequest request = WebRequest.Create("https://www.googleapis.com/oauth2/v1/userinfo?access_token=" + Uri.EscapeDataString(authState.AccessToken)); + WebResponse response = request.GetResponse(); + + if (response != null) { + Stream responseStream = response.GetResponseStream(); + + if (responseStream != null) { + return GoogleGraph.Deserialize(responseStream); + } + } + } + + return null; + } + + /// <summary> + /// Well-known scopes defined by Google. + /// </summary> + /// <remarks> + /// This sample includes just a few scopes. For a complete list of permissions please refer to: + /// https://developers.google.com/accounts/docs/OAuth2Login + /// </remarks> + public static class Scopes { + public const string PlusMe = "https://www.googleapis.com/auth/plus.me"; + + /// <summary> + /// Scopes that cover queries for user data. + /// </summary> + public static class UserInfo { + /// <summary> + /// Gain read-only access to basic profile information, including a user identifier, name, profile photo, profile URL, country, language, timezone, and birthdate. + /// </summary> + public const string Profile = "https://www.googleapis.com/auth/userinfo.profile"; + + /// <summary> + /// Gain read-only access to the user's email address. + /// </summary> + public const string Email = "https://www.googleapis.com/auth/userinfo.email"; + } + + public static class Drive { + /// <summary> + /// Full, permissive scope to access all of a user's files. Request this scope only when it is strictly necessary. + /// </summary> + public const string Default = "https://www.googleapis.com/auth/drive"; + + /// <summary> + /// Per-file access to files created or opened by the app + /// </summary> + public const string File = "https://www.googleapis.com/auth/drive.file"; + + /// <summary> + /// Allows apps read-only access to the list of Drive apps a user has installed + /// </summary> + public const string AppsReadonly = "https://www.googleapis.com/auth/drive.apps.readonly"; + + /// <summary> + /// Allows read-only access to file metadata and file content + /// </summary> + public const string Readonly = "https://www.googleapis.com/auth/drive.readonly"; + + /// <summary> + /// Allows read-only access to file metadata, but does not allow any access to read or download file content + /// </summary> + public const string Metadata = "https://www.googleapis.com/auth/drive.readonly.metadata"; + + /// <summary> + /// Special scope used to let users approve installation of an app + /// </summary> + public const string Install = "https://www.googleapis.com/auth/drive.install"; + } + } + } +} |