OAuth 인증을 처음 접했고 Google의 OAuth 화면에 액세스하려고 시도하면 액세스 코드가 제공되지 않으므로 옵션이 부족합니다. 로그인 화면에 액세스 할 수 있으며 허용 또는 거부를 선택하면 성공 메시지가 나타납니다. 오류는 없지만 때로는 유효하지 않은 프로토콜의 예외를 제공하지만 그 이유는 모르겠습니다.Google OAuth v2 for UWP
나는 here과 here에서 도움을 얻으려고하고 있지만 아무런 효과가 없습니다. 내가 사용하고
코드는 다음과 같습니다 :이 UWP 애플 리케이션에서 그것을 할 수있는 올바른 방법 인 경우
string state = GenerateRandomBase64Url(32);
string code_verifier = GenerateRandomBase64Url(32);
string code_challenge = GenerateBase64urlencodeNoPadding(sha256(code_verifier));
string clientID = "1037832553054-2ktd0l6dop546i1ti312r2doi63sglfe.apps.googleusercontent.com";
string redirectURI = "uwp.app:/oauth2redirect";
string authorizationEndpoint = "https://accounts.google.com/o/oauth2/v2/auth";
string tokenEndpoint = "https://www.googleapis.com/oauth2/v4/token";
string userInfoEndpoint = "https://www.googleapis.com/oauth2/v3/userinfo";
string youtubeScope = "https://www.googleapis.com/auth/youtube";
string code_challenge_method = "S256";
ApplicationDataContainer localSettings = ApplicationData.Current.LocalSettings;
localSettings.Values["state"] = state;
localSettings.Values["code_verifier"] = code_verifier;
string authorizationRequest = string.Format([email protected]"{authorizationEndpoint}?response_type=code&scope={Uri.EscapeDataString(youtubeScope)}&redirect_uri={Uri.EscapeDataString(redirectURI)}&client_id={clientID}&state={state}&code_challenge={code_challenge}&code_challenge_method={code_challenge_method}&login_hint={EmailBox.Text.Trim()}");
string endURL = "https://accounts.google.com/o/oauth2/approval?";
// I don't know if this is actually valid because google says that this Url is not available
Uri startURI = new Uri(authorizationRequest);
Uri endURI = new Uri(endURL);
string result = string.Empty;
try
{
//var success = Windows.System.Launcher.LaunchUriAsync(new Uri(authorizationRequest));
WebAuthenticationResult webAuthenticationResult = await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None, startURI, endURI);
switch (webAuthenticationResult.ResponseStatus)
{
// Successful authentication.
case WebAuthenticationStatus.Success:
result = webAuthenticationResult.ResponseData.ToString();
break;
// HTTP error.
case WebAuthenticationStatus.ErrorHttp:
result = webAuthenticationResult.ResponseErrorDetail.ToString();
break;
default:
result = webAuthenticationResult.ResponseData.ToString();
break;
}
}
catch (Exception ex)
{
result = ex.Message;
}
response.Text = result;
// the string that I get looks like this
// https://accounts.google.com/o/oauth2/approval?as=410b4db829b95fce&pageId=none&xsrfsign=AMt42IIAAAAAWO9e-l2loPR2RJ4_HzjfNiGJbiESOyoh
모르겠어요. 또한 결과에서 얻은 문자열은 URL 뿐이며 Google 예제에서 설명한대로 code
으로 간주되는 항목은 포함되지 않습니다. 누군가 내가 여기서 잘못하고있는 것을 지적 할 수 있습니까? 이것은 간단해야하지만 내가 뭘 잘못하고 있는지 모르겠다. 감사합니다
공식 [코드 샘플] (https://github.com/googlesamples/oauth-apps-for-windows)을 사용하여 Google OAuth v2 for UWP를 테스트했습니다. 그리고'WebAuthenticationBroker.AuthenticateAsync'를 사용하여 웹 인증 결과를 얻었습니다. 하지만 문제를 재현 할 수 없습니다.이 문제에 대해 더 많은 테스트를 수행 할 수 있도록 소스 코드를 제공 할 수 있습니까? –
글쎄,'endURL'의 끝 부분에'? '가 붙은 것만으로도 문제가있는 것 같아요. 여기에 넣었지만 실제 코드에서는 사용하지 않고 어떻게 든 정렬했습니다. 그래도 고마워. – Ahmar