public bool InspectToken(string inputToken, string accessToken) { try { var wr = WebRequest.Create(string.Format(InspectTokenUrl, inputToken, accessToken)); wr.Method = "GET"; wr.Proxy = OAuthHelper.GetProxy(); var wres = wr.GetResponse(); using (var stream = wres.GetResponseStream()) { var result = OAuthHelper.FromJson <FacebookTokenInspectionJsonViewModel>(stream); var part = WorkContext.CurrentSite.As <FacebookSettingsPart>(); if (result.data.app_id == part.ClientId) { return(true); } } } catch (Exception ex) { Logger.Error(ex, ex.Message); } return(false); }
public bool VerifyToken(string tokenToVerify) { try { var wr = WebRequest.Create(string.Format(VerifyTokenUrl, tokenToVerify)); wr.Method = "GET"; wr.Proxy = OAuthHelper.GetProxy(); var wres = wr.GetResponse(); using (var stream = wres.GetResponseStream()) { var result = OAuthHelper.FromJson <GoogleTokenVerifyingJsonViewModel>(stream); var part = WorkContext.CurrentSite.As <GoogleSettingsPart>(); if (result.audience == part.ClientId) { return(true); } } } catch (Exception ex) { Logger.Error(ex, ex.Message); } return(false); }
private string GetAccessToken(WorkContext workContext, string code) { try { var part = workContext.CurrentSite.As <GoogleSettingsPart>(); var clientId = part.ClientId; var clientSecret = _oauthHelper.Decrypt(part.Record.EncryptedClientSecret); var urlHelper = new UrlHelper(workContext.HttpContext.Request.RequestContext); var redirectUrl = new Uri( workContext.HttpContext.Request.Url, urlHelper.Action("GoogleAuth", "Account", new { area = "Teeyoot.Account" }) ).ToString(); var wr = WebRequest.Create(TokenRequestUrl); wr.Proxy = OAuthHelper.GetProxy(); wr.ContentType = "application/x-www-form-urlencoded"; wr.Method = "POST"; using (var stream = wr.GetRequestStream()) using (var ws = new StreamWriter(stream, Encoding.UTF8)) { ws.Write("code={0}&", code); ws.Write("client_id={0}&", clientId); ws.Write("client_secret={0}&", clientSecret); ws.Write("redirect_uri={0}&", redirectUrl); ws.Write("grant_type=authorization_code"); } var wres = wr.GetResponse(); using (var stream = wres.GetResponseStream()) { var result = OAuthHelper.FromJson <GoogleAccessTokenJsonModel>(stream); return(result.access_token); } } catch (Exception ex) { Logger.Error(ex, ex.Message); } return(null); }
public string GetEmailAddress(string token) { try { var wr = WebRequest.Create(string.Format(EmailRequestUrl, token)); wr.Method = "GET"; wr.Proxy = OAuthHelper.GetProxy(); var wres = wr.GetResponse(); using (var stream = wres.GetResponseStream()) { var result = OAuthHelper.FromJson <FacebookEmailAddressJsonViewModel>(stream); return(result != null && result.verified ? result.email : null); } } catch (Exception ex) { Logger.Error(ex, ex.Message); } return(null); }