/// <summary> /// Creates the Authorization Url, that the user will visit to allow your application to access their user account. /// For more information on how OAuth2 on Imgur works, visit their Developer Section (https://api.imgur.com/oauth2) /// </summary> /// <param name="responseType"> /// The type of response you want to use. It's recomended that; /// - Pin: Desktop/Server/Mobile Applications /// - Code: Desktop/Server/Mobile Applications /// - Token: Javascript Applications /// </param> /// <param name="state">The state you want to pass through auth. This will be given back to you from the re-direct url if you use Code or Token Authentication.</param> public string CreateAuthorizationUrl(OAuth2Type responseType, string state = null) { var queryStrings = new Dictionary <string, string> { { "client_id", ClientId } }; if (state != null) { queryStrings.Add("state", state); } OAuthType = responseType; switch (responseType) { case OAuth2Type.Code: queryStrings.Add("response_type", "code"); break; case OAuth2Type.Token: queryStrings.Add("response_type", "token"); break; case OAuth2Type.Pin: queryStrings.Add("response_type", "pin"); break; default: throw new InvalidOperationException(); } return(queryStrings.ToQueryString(AuthorizationEndpoint)); }
/// <summary> /// Generates a grant_type from the OAuth2 Type used in this authentication /// </summary> /// <param name="oAuth2Type"></param> private static string GrantTypeFromOAuthType(OAuth2Type oAuth2Type) { switch (oAuth2Type) { case OAuth2Type.Code: return("authorization_code"); case OAuth2Type.Pin: return("pin"); case OAuth2Type.Token: return("token"); default: throw new ArgumentOutOfRangeException("oAuth2Type"); } }
/// <summary> /// Generates a grant_type from the OAuth2 Type used in this authentication /// </summary> /// <param name="oAuth2Type"></param> private static string GrantTypeFromOAuthType(OAuth2Type oAuth2Type) { switch (oAuth2Type) { case OAuth2Type.Code: return "authorization_code"; case OAuth2Type.Pin: return "pin"; case OAuth2Type.Token: return "token"; default: throw new ArgumentOutOfRangeException("oAuth2Type"); } }
/// <summary> /// Creates the Authorization Url, that the user will visit to allow your application to access their user account. /// For more information on how OAuth2 on Imgur works, visit their Developer Section (https://api.imgur.com/oauth2) /// </summary> /// <param name="responseType"> /// The type of response you want to use. It's recomended that; /// - Pin: Desktop/Server/Mobile Applications /// - Code: Desktop/Server/Mobile Applications /// - Token: Javascript Applications /// </param> /// <param name="state">The state you want to pass through auth. This will be given back to you from the re-direct url if you use Code or Token Authentication.</param> public string CreateAuthorizationUrl(OAuth2Type responseType, string state = null) { var queryStrings = new Dictionary<string, string> { { "client_id", ClientId } }; if (state != null) queryStrings.Add("state", state); OAuthType = responseType; switch (responseType) { case OAuth2Type.Code: queryStrings.Add("response_type", "code"); break; case OAuth2Type.Token: queryStrings.Add("response_type", "token"); break; case OAuth2Type.Pin: queryStrings.Add("response_type", "pin"); break; default: throw new InvalidOperationException(); } return queryStrings.ToQueryString(AuthorizationEndpoint); }