Programing

페이스 북 오류 '인증 코드 확인 오류'

lottogame 2021. 1. 9. 09:19
반응형

페이스 북 오류 '인증 코드 확인 오류'


매우 이상한 오류입니다. 나는 gide http://developers.facebook.com/docs/authentication/ 사용 합니다. 그래서 fb에 대한 요청을 만들고 redirect_uri를 전달합니다. 나는 localhost에서 테스트 사이트를 사용합니다. 그래서 내가 통과하면

redirect_uri = http : //localhost/test_blog/index.php

잘 작동하지만 통과하면

redirect_uri = http : //localhost/test_blog/index.php? r = site / oauth2

일을 원하지 않습니다. 나는 사용하려고한다

redirect_uri =. urlencode ( ' http : //localhost/test_blog/index.php? r = site / oauth2 )

하지만 작동하지 않습니다. 설명하려고합니다. 성공적으로 코드를 얻었지만 https://graph.facebook.com/me?access_token에 액세스 하면 '인증 코드 유효성 검사 오류'오류가 발생합니다. 나는 evering을 확인했고, 오류는 ? r = site / oauth2에 있지만 매개 변수를 전달해야 누군가가 나를 도울 수 있습니까? http://forum.developers.facebook.net/viewtopic.php?id=70855 게시물을 읽었 지만 아무것도 작동하지 않습니다.


유효한 redirect_uri를 만드는 것에 대해 현재 (2011 년 3 월 현재) 문서화되지 않은 요구 사항이 있습니다.

먼저, 인증 할 redirect_uri 매개 변수와 access_token이 일치해야합니다 .

분명히 Facebook (또는 오히려 OAuth2)은 access_token 요청에 대해 반환 된 코드를 인코딩하기 위해 내부 키로 redirect_uri를 사용하고 있습니다. 사이트를 다시 확인하기 때문에 약간 영리합니다. 다른 방법으로는 redirect_uri 매개 변수가 필요하지 않은 access_token 요청에 필요한 이유를 설명합니다.

둘째, redirect_uri에 많은 특수 문자를 사용할 수 없습니다 .

매개 변수가 전혀 전달 될 수 있는지에 대한 많은 논의가 분노합니다. 그들은 유효한 문자가 제한되어 있지만 아무도 내가 아는 목록을 게시하지 않았습니다. url / html 인코딩과 같은 전통적인 방법은 백분율 (%)이 유효하지 않기 때문에 실패합니다. 슬래시 (/)도 유효하지 않으므로 중첩 된 리디렉션 URL은 항상 실패합니다. 특수 문자 제한을 극복하는 유일한 방법은 매개 변수 값을 base64로 인코딩하는 것입니다. ASP.NET을 사용하는 경우 Convert.ToBase64를 찾습니다.

마지막으로 이것은 부수적 인 내용입니다. 많은 프로그래머가 간단한 해결책이 type = client_cred를 전달하는 것이라는 잘못된 정보를 전달하고 있습니다. 이로 인해 인증에서 요청한 일부 권한에 대한 액세스가 제한 될 수 있습니다. 그것은 바람직하지 않습니다.


테스트 할 때 하루 종일 동일한 문제가 발생했습니다 redirect_uri=http://localhost:8000(로 인코딩 됨 http%3A%2F%2Flocalhost%3A8000) ...

해결책은 단순히 /uri 끝에 후행 슬래시를 넣는 것 입니다. 그래서 redirect_uri=http://localhost:8000/(로 인코딩 됨 http%3A%2F%2Flocalhost%3A8000%2F).

다시, redirect_uri두 요청에 대해 동일한 지 확인하십시오 .


나는이 문제가 있었다. 동일한 $ var를 가진 클래스를 사용했기 때문에 URL이 동일하다는 사실을 알고 있었지만 JSON 응답에서 400 응답과 해당 오류를 계속 받았습니다.

내가 한 유일한 일은 내 redirect_uri를 다음에서 변경하는 것입니다.

http://myredirecturi.com

...에

http://myredirecturi.com/

예, 후행 슬래시를 추가하면 작동했습니다.


실제로 인코딩 할 필요는 없습니다. redirect_url 끝에 '/'를 넣으면 모든 것이 정상입니다!


Aaron Wheeler가 제공 한 정보의 일부가 잘못되었습니다.

'redirect_uri'매개 변수가 두 요청에서 동일해야한다는 것은 사실이지만, 추가 URL에주의하는 한 일반 URL을 URL 인코딩 하고 'redirect_url'매개 변수의 값으로 사용하는 것이 완벽하게 가능합니다. 인라인 URL을 인코딩합니다.

예를 들어, facebook이 다음 URL로 리디렉션되기를 원합니다.

http://www.mysite.com/Users/oAuthComplete?my_param_1=/Party/pants

사용자를 다음으로 리디렉션하려고합니다.

'https://www.facebook.com/dialog/oauth?client_id=12345&redirect_uri='
. urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1=/Party/pants');

/Party/Pants잘못된 URL 생성하여 실패 합니다.

그러나 리디렉션

'https://www.facebook.com/dialog/oauth?client_id=12345&redirect_uri='
.urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1='
.urlencode('/Party/pants'));

예상대로 작동합니다.

두 번째 인증 응용 프로그램 요청에서 반환 된 redrect_uri 값을 사용하는 경우 다시 URL 인코딩을 수행해야 합니다. 값은 $ _GET superglobal을 채울 때 자동으로 URL 디코딩됩니다 . -이게 나를 넘어 뜨린 것입니다.

'https://graph.facebook.com/oauth/access_token?client_id=12345&&client_secret=SECRET&code=1234567'
.urlencode('http://www.mysite.com/Users/oAuthComplete?my_param_1='
.urlencode($_GET['my_param_1']));

P.s. In your actual code, I'd recommend using sprintf() rather than chaining string together like in my example, for better readability.


From what I can see, the problem here is that the redirect_uri must end with '/' and not contain '?' or other special characters. I think that is why you are getting 'Error validating verification code'. This error only appears if you are using file_get_contents(), and not when using the facebook php library. This is the solution for php, don't know if this error appears in other SDK's.


I'm not sure if it will help, but i would suggest to encode only values in the url. Not the whole thing. eg:

redirect_uri='http://localhost/test_blog/index.php?r='.urlencode('site/oauth2');

I was having the pb and finally fix it adding the type=client_cred parameter in the url.


I just had the same problem.

Admittedly, I am a super n00b so excuse me if this solution doesnt make any sense in actual practice.

I simply set a short fuse cookie (1-2 min) with a test variable in the page with my FB Connect button. When FB came back with information to my data parsing/handling script I checked for this cookie where I was redirecting it and if found, directed the user to the proper URL using header:location.

Of course some browsers/users etc disable cookies. This obviously wont work there (maybe use a session var and destroy it in the fb data handler?) I am sure there is a better way to do it but at the moment, this bandaid works.


The answer for me was this:

$user = $facebook->getUser();     
if (!$user) {
    $loginUrl = $facebook->getLoginUrl(array(
        'scope' => '',
        'redirect_uri' => $this->domain,
    ));
    print('<script> top.location.href=\'' . $loginUrl . '\'</script>');
}

I've been cracking my head a long time before I found this solution, seeming I am not the only one with this issue I hope this works for you to!


I noticed you are using Yii which I'm using as well and had the same problem for half the day. As mentioned, the problem is the special characters in your URL i.e. r=site/oath2

You can fix it by enabling pretty URLS in your config so that your URL becomes index.php/site/oath2

It seems to work without the trailing slash though.

ReferenceURL : https://stackoverflow.com/questions/4386691/facebook-error-error-validating-verification-code

반응형