Search code examples
springoauth-2.0spring-socialspring-social-google

How to recover from a Spring Social ExpiredAuthorizationException


I am trying to implement Google Oauth2 with Spring Social and spring-social-google. Initial authentication works fine. However after some time the authentication expires and I am hit by

org.springframework.social.ExpiredAuthorizationException: The authorization has expired.

How can you recover from this exception? Is it possible to somehow refresh the authorization?


Solution

  • Try to send additional access_type=offline paramter during authorization. It may looks something like this:

    <form ...>
        .....
        <input type="hidden" name="access_type" value="offline"/>
    </form>
    

    Normally in this case authorization will be refreshed automatically for you. See this entry for more details.