Google Get AccessToken

1 . Auth Code 구하기

  • 플레이콘솔에 앱을 등록하고 아래 주소로 Auth Code를 구함
https://accounts.google.com/o/oauth2/v2/auth?scope=https%3A//www.googleapis.com/auth/drive.metadata.readonly&access_type=offline&include_granted_scopes=true&response_type=code&state=some&client_id=앱클라이언트ID&redirect_uri=redirect받을주소(GET으로 받을페이지) 
  • 위 사진에 보이는 ‘code’가 Auth Code이다.
  • Auth Code를 새로 추출하기 위해선 &prompt=consent 를 추가

2 . Refresh Token 생성

  • 위에 구한 Authcode와 ClientID, ClientSecret으로 Token을 구한다
$data = array('code'=>$_GET['code'],
         'client_id'=>"173073",
         'client_secret'=>"O68oj",
         'redirect_uri'=>"http://localhost:8011/receive.php",
         grant_type' => "authorization_code"         
);
  • RefreshToken은 만료시간이 존재하지 않는다.
  • 아래와 같은 조건에서 토큰이 만료된다.
  • AccessToken은 만료시간이 존재하면 Refresh Token을 통하여 구해온다.

3 . AccessToken 갱신

구한 RefreshToken을 이용하여 AccessToken을 갱신

Published by

shotan

Hi i'm cho

Leave a Reply

Your email address will not be published. Required fields are marked *