public bool RefreshAccessToken() { if (OAuth2Info.CheckOAuth(AuthInfo) && !string.IsNullOrEmpty(AuthInfo.Token.refresh_token)) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("refresh_token", AuthInfo.Token.refresh_token); args.Add("client_id", AuthInfo.Client_ID); args.Add("client_secret", AuthInfo.Client_Secret); args.Add("grant_type", "refresh_token"); string response = GoogleUploader.SendRequestMultiPart("https://accounts.google.com/o/oauth2/token", args); if (!string.IsNullOrEmpty(response)) { OAuth2Token token = JsonConvert.DeserializeObject <OAuth2Token>(response); if (token != null && !string.IsNullOrEmpty(token.access_token)) { token.UpdateExpireDate(); string refresh_token = AuthInfo.Token.refresh_token; AuthInfo.Token = token; AuthInfo.Token.refresh_token = refresh_token; return(true); } } } return(false); }
public bool GetAccessToken(string code) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("code", code); args.Add("client_id", AuthInfo.Client_ID); args.Add("client_secret", AuthInfo.Client_Secret); args.Add("redirect_uri", RedirectMethod); args.Add("grant_type", "authorization_code"); string response = GoogleUploader.SendRequestURLEncoded(HttpMethod.POST, TokenEndpoint, args); if (!string.IsNullOrEmpty(response)) { OAuth2Token token = JsonConvert.DeserializeObject <OAuth2Token>(response); if (token != null && !string.IsNullOrEmpty(token.access_token)) { token.UpdateExpireDate(); AuthInfo.Token = token; return(true); } } return(false); }
public bool GetAccessToken(string code) { Dictionary <string, string> args = new Dictionary <string, string>(); args.Add("code", code); args.Add("client_id", AuthInfo.Client_ID); args.Add("client_secret", AuthInfo.Client_Secret); args.Add("redirect_uri", "urn:ietf:wg:oauth:2.0:oob"); args.Add("grant_type", "authorization_code"); string response = GoogleUploader.SendRequestMultiPart("https://accounts.google.com/o/oauth2/token", args); if (!string.IsNullOrEmpty(response)) { OAuth2Token token = JsonConvert.DeserializeObject <OAuth2Token>(response); if (token != null && !string.IsNullOrEmpty(token.access_token)) { token.UpdateExpireDate(); AuthInfo.Token = token; return(true); } } return(false); }
public OAuthUserInfo GetUserInfo() { string response = GoogleUploader.SendRequest(HttpMethod.GET, UserInfoEndpoint, null, GetAuthHeaders()); if (!string.IsNullOrEmpty(response)) { return(JsonConvert.DeserializeObject <OAuthUserInfo>(response)); } return(null); }