protected override Uri GetServiceLoginUrl(Uri returnUrl) { var builder = new UriBuilder(_authorizationEndpoint); var args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("client_id", _appId); args.Add("redirect_uri", GoogleProviderAuthorizer.NormalizeHexEncoding(returnUrl.AbsoluteUri)); args.Add("scope", string.Join(" ", this._scopes)); GoogleProviderAuthorizer.AppendQueryArgs(builder, args); return(builder.Uri); }
protected override string QueryAccessToken(Uri returnUrl, string authorizationCode) { var args = new Dictionary <string, string>(); args.Add("response_type", "code"); args.Add("code", authorizationCode); args.Add("client_id", _appId); args.Add("client_secret", _appSecret); args.Add("redirect_uri", GoogleProviderAuthorizer.NormalizeHexEncoding(returnUrl.AbsoluteUri)); args.Add("grant_type", "authorization_code"); string query = "?" + GoogleProviderAuthorizer.CreateQueryString(args); string data = HttpPost(_tokenEndpoint, query); if (string.IsNullOrEmpty(data)) { return(null); } JObject jObject = JObject.Parse(data); return((string)jObject["access_token"]); }
protected override IDictionary <string, string> GetUserData(string accessToken) { var userData = new Dictionary <string, string>(); using (WebClient client = new WebClient()) { using (Stream stream = client.OpenRead(_userInfoEndpoint + "?access_token=" + GoogleProviderAuthorizer.EscapeUriDataStringRfc3986(accessToken))) { using (StreamReader reader = new StreamReader(stream)) { JObject jObject = JObject.Parse(reader.ReadToEnd()); userData.Add("id", (string)jObject["id"]); userData.Add("username", (string)jObject["email"]); userData.Add("name", (string)jObject["given_name"] + " " + (string)jObject["family_name"]); userData.Add("picture", (string)jObject["picture"]); } } } return(userData); }