/// <summary> /// Attempts to parse the specified <paramref name="value"/> into an instance of <see cref="GoogleScope"/>. /// </summary> /// <param name="value">The alias of a known scope.</param> /// <param name="scope">The scope if a match was found.</param> /// <returns><c>true</c> if a matching scope was found; otherwise <c>false</c>.</returns> public static bool TryParseScope(string value, out GoogleScope scope) { scope = null; if (string.IsNullOrWhiteSpace(value)) { return(false); } value = value.Trim(); switch (value) { case "https://www.googleapis.com/auth/userinfo.profile": scope = GoogleScopes.Profile; return(true); case "https://www.googleapis.com/auth/userinfo.email": scope = GoogleScopes.Email; return(true); default: scope = GoogleScopeGroup.GetAll().SelectMany(x => x.Scopes).FirstOrDefault(x => x.Alias == value); return(scope != null); } }
/// <summary> /// Initializes a new instance with the specified options. /// </summary> /// <param name="state">The state of the application.</param> /// <param name="scope">The scope of the application.</param> /// <param name="accessType">Whether the application should be enabled for offline access.</param> /// <param name="prompt">A list of prompts to present the user. If <see cref="GooglePromptOption.None"/>, the user will be prompted only the first time your app requests access.</param> public GoogleAuthorizeOptions(string state, string scope, GoogleAccessType accessType, GooglePromptOption prompt) { State = state; Scope = new GoogleScope(scope); AccessType = accessType; Prompt = prompt; }
private string JoinScopes(GoogleScope scope) { string result = string.Empty; bool needsPlus = false; foreach (GoogleScope value in typeof(GoogleScope).GetEnumValues()) { if (scope.HasFlag(value)) { if (needsPlus) { result += "+"; } else { needsPlus = true; } result += value.GetAttribute <EnumMemberAttribute>().Value; } } return(result); }
/// <summary> /// Initializes a new instance with the specified options. /// </summary> /// <param name="state">The state of the application.</param> /// <param name="scope">The scope of the application.</param> public GoogleAuthorizeOptions(string state, string scope) { State = state; Scope = new GoogleScope(scope); }
public string GetAdditionalScope(GoogleScope scope) { return($"+{JoinScopes(scope)}"); }
public Uri CreateAuthUri(IYoutubeClient client, YoutubeRedirectUri redirectUri, GoogleScope scope) { string scopeString = JoinScopes(scope); string redirectUriString = redirectUri.GetAttribute <EnumMemberAttribute>().Value; string authRequestString = $"https://accounts.google.com/o/oauth2/auth?client_id={client.Id}&redirect_uri={redirectUriString}&scope={scopeString}&response_type=code&approval_prompt=force&access_type=offline"; return(new Uri(authRequestString)); }