How to make Google sign-in token valid for longer than 1 hour?

后端 未结 2 2266
悲哀的现实
悲哀的现实 2021-02-02 02:59

I have implemented google sign-in successfully.

I am able to authenticate user and in response I receive token. However the token expires in 1 hour.

expire

2条回答
  •  谎友^
    谎友^ (楼主)
    2021-02-02 03:09

    Access tokens are short lived and only last for one hour this is not something you can extend.

    What you need to do is take the refresh token and get a new access token.

    example:

    You take the refresh_token that you got from your initial request and HTTP Post it to: Note: grant_type=refresh_token

    https://accounts.google.com/o/oauth2/token
    client_id={ClientId}.apps.googleusercontent.com&client_secret={ClientSecret}&refresh_token=1/ffYmfI0sjR54Ft9oupubLzrJhD1hZS5tWQcyAvNECCA&grant_type=refresh_token

    response

    {
    "access_token" : "ya29.1.AADtN_XK16As2ZHlScqOxGtntIlevNcasMSPwGiE3pe5ANZfrmJTcsI3ZtAjv4sDrPDRnQ",
    "token_type" : "Bearer",
    "expires_in" : 3600
    }
    

提交回复
热议问题