Search code examples
javagoogle-apiauthorizationgoogle-oauthoauth-2.0

Google Oauth 2.0 minimum user interaction


We have a requriement, our users want to interact with various Google API's and therefore we require OAuth2.0 authorisation against Google's Authorisation Server.

Our constraint is that we are using a single web page front end and DO NOT want to redirect away from our page in order to obtain user authorisation.

In the ideal scenario, the user would check a box or click a button on our webpage, then using this input, we would receive access tokens and refresh tokens without the user interacting directly with a Google. Would such a idea be possible or is some form of user interaction a must in the intial step.

We have read some references to piggybacking with Oauth2.0 and OpenConnectId, we are however unsure about the applicability to such a scenario. Any advice or input would be appreciated

Thanks in advance


Solution

  • I guess you need the flow of Refresh Token of OAuth2.

    Refresh Token of OAuth2:

    A refresh token is a string representing the authorization granted to the client by the resource owner. The string is usually opaque to the client. The token denotes an identifier used to retrieve the authorization information. Unlike access tokens, refresh tokens are intended for use only with authorization servers and are never sent to resource servers.

      +--------+                                           +---------------+
      |        |--(A)------- Authorization Grant --------->|               |
      |        |                                           |               |
      |        |<-(B)----------- Access Token -------------|               |
      |        |               & Refresh Token             |               |
      |        |                                           |               |
      |        |                            +----------+   |               |
      |        |--(C)---- Access Token ---->|          |   |               |
      |        |                            |          |   |               |
      |        |<-(D)- Protected Resource --| Resource |   | Authorization |
      | Client |                            |  Server  |   |     Server    |
      |        |--(E)---- Access Token ---->|          |   |               |
      |        |                            |          |   |               |
      |        |<-(F)- Invalid Token Error -|          |   |               |
      |        |                            +----------+   |               |
      |        |                                           |               |
      |        |--(G)----------- Refresh Token ----------->|               |
      |        |                                           |               |
      |        |<-(H)----------- Access Token -------------|               |
      +--------+           & Optional Refresh Token        +---------------+
    
               Figure: Refreshing an Expired Access Token
    

    The flow illustrated in Figure 2 includes the following steps:

    (A) The client requests an access token by authenticating with the authorization server and presenting an authorization grant.

    (B) The authorization server authenticates the client and validates the authorization grant, and if valid, issues an access token and a refresh token.

    (C) The client makes a protected resource request to the resource server by presenting the access token.

    (D) The resource server validates the access token, and if valid, serves the request.

    (E) Steps (C) and (D) repeat until the access token expires. If the client knows the access token expired, it skips to step (G); otherwise, it makes another protected resource request.

    (F) Since the access token is invalid, the resource server returns an invalid token error.

    (G) The client requests a new access token by authenticating with the authorization server and presenting the refresh token. The client authentication requirements are based on the client type and on the authorization server policies.

    (H) The authorization server authenticates the client and validates the refresh token, and if valid, issues a new access token (and, optionally, a new refresh token).

    Resource Refs

    According to you scenery, you might try to use Ajax Call to fulfill your requirements.