3
하지 않습니다 나는 Google 로그인에서 사용자에게 FIRSTNAME 및 LASTNAME를받을 필요가있다.구글 로그인이 날 GIVEN_NAME주고 FAMILY_NAME
internal static string GoogleAppId = "XXXXXXXXXXXXX-scvpbtaoijuciinu1oneu7ijqtdvcpce.apps.googleusercontent.com";
internal static string GoogleAppSecret = "XXXXXXXXXXXUJuZNHhf6-8";
internal static Uri GoogleStartUri = new Uri("https://accounts.google.com/o/oauth2/auth?client_id=" + Uri.EscapeDataString(GoogleAppId) + "&redirect_uri=" + Uri.EscapeDataString("urn:ietf:wg:oauth:2.0:oob") + "&response_type=code&scope=" + Uri.EscapeDataString("profile openid https://www.googleapis.com/auth/plus.login https://www.googleapis.com/auth/plus.me email"));
private string GoogleCallbackUrl = "urn:ietf:wg:oauth:2.0:oob";
internal static Uri GoogleEndUri = new Uri("https://accounts.google.com/o/oauth2/approval?");
public static void AuthenticateAndContinue()
{
StringBuilder googleUrl = new StringBuilder();
googleUrl.Append("https://accounts.google.com/o/oauth2/auth?client_id=");
googleUrl.Append(Uri.EscapeDataString(GoogleAppId));
googleUrl.Append("&scope=openid%20email%20profile");
googleUrl.Append("&redirect_uri=");
googleUrl.Append(Uri.EscapeDataString(GoogleCallbackUrl));
googleUrl.Append("&response_type=code");
Uri startUri = new Uri(googleUrl.ToString());
WebAuthenticationBroker.AuthenticateAndContinue(startUri, GoogleEndUri, null, WebAuthenticationOptions.UseTitle);
}
public static async Task<string> GetToken(string code)
{
var client = new HttpClient();
var auth = await client.PostAsync("https://accounts.google.com/o/oauth2/token", new FormUrlEncodedContent(new[]
{
new KeyValuePair<string, string>("code", code),
new KeyValuePair<string, string>("client_id",GoogleAppId),
new KeyValuePair<string, string>("client_secret",GoogleAppSecret),
new KeyValuePair<string, string>("grant_type","authorization_code"),
new KeyValuePair<string, string>("redirect_uri","urn:ietf:wg:oauth:2.0:oob"),
//new KeyValuePair<string, string>("redirect_uri","http://localhost")
}));
var data = await auth.Content.ReadAsStringAsync();
var response = JsonConvert.DeserializeObject<TokenResponse>(data);
System.Diagnostics.Debug.WriteLine(response.id_token);
return response.id_token;
}
internal async void Continue(IContinuationActivatedEventArgs args)
{
if (args.Kind == ActivationKind.WebAuthenticationBrokerContinuation)
{
var data = ((WebAuthenticationBrokerContinuationEventArgs)args).WebAuthenticationResult.ResponseData.Split('&')[0];
var code = data.Split('=')[1];
System.Diagnostics.Debug.WriteLine($"code: {code}");
var token = await GoogleManager.GetToken(code);
}
}
그럼 내가 여기 토큰을 넣어 : 이 내 코드입니다
https://www.googleapis.com/oauth2/v3/tokeninfo?id_token= {0}
나는 JSON하지만 FAMILY_NAME 및 GIVEN_NAME가 누락받을 :
{
"iss": "accounts.google.com",
"at_hash": "9Nxxxxxxxxxxxxxxx9uBNHA",
"aud": "99655070360-scvpbtaoijuXXXXXXXXXXXXXXXXvcpce.apps.googleusercontent.com",
"sub": "106XXXXXXXXXXXX86619603",
"email_verified": "true",
"azp": "996550XXXXXXXXXXXXXXXijqtdvcpce.apps.googleusercontent.com",
"email": "[email protected]",
"iat": "1473XXXXXXXXXX",
"exp": "14738665XXX",
"alg": "RS256",
"kid": "96bffd2afXXXXXXXXXXXXXXXXXXXXXXXX"
}
내가 뭘 잘못하고 있니?