//----------------------------------------------------------------------- // // Copyright (c) Outercurve Foundation. All rights reserved. // //----------------------------------------------------------------------- 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 }; /// /// Initializes a new instance of the class. /// 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; } /// /// Well-known scopes defined by Google. /// /// /// This sample includes just a few scopes. For a complete list of permissions please refer to: /// https://developers.google.com/accounts/docs/OAuth2Login /// public static class Scopes { public const string PlusMe = "https://www.googleapis.com/auth/plus.me"; /// /// Scopes that cover queries for user data. /// public static class UserInfo { /// /// Gain read-only access to basic profile information, including a user identifier, name, profile photo, profile URL, country, language, timezone, and birthdate. /// public const string Profile = "https://www.googleapis.com/auth/userinfo.profile"; /// /// Gain read-only access to the user's email address. /// public const string Email = "https://www.googleapis.com/auth/userinfo.email"; } public static class Drive { /// /// Full, permissive scope to access all of a user's files. Request this scope only when it is strictly necessary. /// public const string Default = "https://www.googleapis.com/auth/drive"; /// /// Per-file access to files created or opened by the app /// public const string File = "https://www.googleapis.com/auth/drive.file"; /// /// Allows apps read-only access to the list of Drive apps a user has installed /// public const string AppsReadonly = "https://www.googleapis.com/auth/drive.apps.readonly"; /// /// Allows read-only access to file metadata and file content /// public const string Readonly = "https://www.googleapis.com/auth/drive.readonly"; /// /// Allows read-only access to file metadata, but does not allow any access to read or download file content /// public const string Metadata = "https://www.googleapis.com/auth/drive.readonly.metadata"; /// /// Special scope used to let users approve installation of an app /// public const string Install = "https://www.googleapis.com/auth/drive.install"; } } } }