| 제목 | oauth 구현관련 질문입니다. | ||
|---|---|---|---|
| 글쓴이 | 예나아범 | 작성시각 | 2014/10/17 19:09:37 |
|
|
|||
|
중국 SNS와 로그인연동을 위해 oauth 구현하고 있습니다. 일단 사용자가 동의하면 나오는 키는 받았는데 이걸 토스해서 access token을 받는데서 계속 에러가 나네요. 웅파님이 올려주신 네이버 로그인 참조해서 만들어 보기는 했는데.... 제 호스팅에서는 file_get_contents 함수를 쓰면 에러가 발생해서 curl로 구현을 해봤습니다. 일단 값이 넘어가니까 뭔가 에러값이 돌아오는거 같은데 도저히 어디가 잘못된건지 모르겠네요. ㅠㅠ 소스 보시고 답변부탁드립니다.
public function weibo()
{
$this->config->load('oauth');
$key = $this->config->item('weibo');
$key['response_type'] = 'code';
$key['redirect_url'] = site_url('oauth/weibo');
$url = 'https://api.weibo.com/oauth2/authorize?client_id='.urlencode($key['client_id']).'&response_type=code&redirect_uri='.urlencode($key['redirect_url']);
if(!$_GET['code']) {
header('Location: '.$url);
}
if($_GET['code'])
{
$key['code'] = $_GET['code'];
}
$url2 = 'https://api.weibo.com/oauth2/access_token';
$access_token_parameters = array (
'client_id' => $key['client_id'],
'client_secret' => $key['client_secret'],
'grant_type' => 'authorization_code',
'redirect_uri' => $key['redirect_url'],
'code' => $key['code']
);
$ch = curl_init($url2);
curl_setopt ($ch, CURLOPT_POST, true);
curl_setopt ($ch, CURLOPT_POSTFIELDS, $access_token_parameters);
curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt ($ch, CURLOPT_SSL_VERIFYPEER, false);
$json = curl_exec($ch);
curl_close($ch);
$data = json_encode($json, true);
echo $data;
}
아래는 해당 개발 문서 내용입니다. 1. 引导需要授权的用户到如下地址:권한을 받고자 하는 사용자에게 아래 주소를 보낸다. https://api.weibo.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&response_type=code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI
https://api.weibo.com/oauth2/access_token?client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET&grant_type=authorization_code&redirect_uri=YOUR_REGISTERED_REDIRECT_URI&code=CODE (其中client_id=YOUR_CLIENT_ID&client_secret=YOUR_CLIENT_SECRET可以使用basic方式加入header中)
{ "access_token":"SlAV32hkKG", "remind_in ":3600, "expires_in":3600 }
|
|||
| 다음글 | 쇼핑몰에서 파일 업로드 할떄... (5) | ||
| 이전글 | 중복 로그인 이벤트 발생 시 로그인 시간 딜레이? (2) | ||
|
변종원(웅파)
/
2014/10/17 19:17:57 /
추천
0
소스상로 첫번째, 두번째 변수값을 선언한 곳이 없습니다.
|
|
예나아범
/
2014/10/17 19:26:46 /
추천
0
웅파님 어떤 변수값 말씀하시는지요? $key['client_id'],$key['client_secret'] 라면 config에 파일로 $key = $this->config->item('weibo'); 이런식으로 먼저 불러왔습니다.
|
|
예나아범
/
2014/10/17 20:37:39 /
추천
0
$url2 = 'https://api.weibo.com/oauth2/access_token?client_id='.urlencode($key['client_id']).'&client_secret='.urlencode($key['client_secret']).'&grant_type=authorization_code&redirect_uri='.urlencode($key['redirect_url']).'&code='.urlencode($key['code']); $ch = curl_init(); curl_setopt ($ch, CURLOPT_URL, $url2); curl_setopt ($ch, CURLOPT_POST, true); curl_setopt ($ch, CURLOPT_RETURNTRANSFER, 1); $json = curl_exec($ch); $a = curl_error($ch); curl_close($ch); $data = json_encode($json, true);이걸로 해결됐네요... 힘들다 ㅠㅠ |