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", QQProviderAuthorizer.NormalizeHexEncoding(returnUrl.AbsoluteUri)); args.Add("scope", string.Join(" ", this._scopes)); QQProviderAuthorizer.AppendQueryArgs(builder, args); return(builder.Uri); }
//protected override IDictionary<string, string> GetUserData(string accessToken) //{ // var userData = new Dictionary<string, string>(); // using (var client = new WebClient()) // { // using (var stream = client.OpenRead(UserInfoEndpoint + "?access_token=" + QQProviderAuthorizer.EscapeUriDataStringRfc3986(accessToken))) // { // using (var 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"]); // } // } // } // return userData; //} 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", QQProviderAuthorizer.NormalizeHexEncoding(returnUrl.AbsoluteUri)); args.Add("grant_type", "authorization_code"); string query = "?" + QQProviderAuthorizer.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 (var client = new WebClient()) { using (var stream = client.OpenRead(UserInfoEndpoint + "?access_token=" + QQProviderAuthorizer.EscapeUriDataStringRfc3986(accessToken))) { using (var reader = new StreamReader(stream)) { JObject jObject = JObject.Parse(reader.ReadToEnd()); userData.Add("id", (string)jObject["openid"]); //userData.Add("username", (string)jObject["email"]); userData.Add("name", (string)jObject["nickname"]); } } } return(userData); }