0

I'm writing a web application where I'm getting an authorization code with which I'm able to get an access token. But this token expires in an hour's time. So how do I get a refresh token from the authorization code and use the same refresh token to get a new access token each time the old one expires?

I'm working with Java and Jsp.

mabi
  • 5,279
  • 2
  • 43
  • 78
Arun
  • 21
  • 1
  • 6

1 Answers1

0

Assuming you're talking about get access/refresh token from Google. To get a refresh token, you should set access_type=offline when you request the authorization code. You can find details in the Google OAuth2 web server flow documentation. Alternatively you can choose to use Google OAuth2 client library for Java if you don't want to implement the flows by yourself.

mengcheng
  • 331
  • 1
  • 3
  • but assigning the access_type=offline, the user is redirected to the consent screen each time he/she logs in. i want the consent screen to be displayed only one time to the user. amid, thanks for the response. – Arun May 28 '14 at 10:08
  • You only need to ask the user's permission once. After the user grants the permission, you'll receive an authorization code and you can exchange it for a refresh token. To avoid prompting the user every time, you need save the refresh token in a safe storage and use it to get a new access token when the current one is expired. – mengcheng Jun 02 '14 at 16:04