ERROR Caused by com.google.api.client.auth.oauth2.TokenResponseException 400 Bad Request - invalid_g

During the reconcilation from OpenIDM to the ICF google apps connector, the following error response would occur. ERROR Caused by com.google.api.client.auth.oauth2.TokenResponseException 400 Bad Request - invalid_grant
September 12, 2017
OpenIDMIDMGoogleGoogle-AppsICFreconciliation

THE ERROR

When reviewing the connector reconciliation, it will often fail after 67 seconds.

The likely error is shown as follows:


THE SOLUTION

You certainly need to create the client within the Google API Developers. The client secret and the client ID will be presented once you've logged into the https://console.developers.google.com/apis/credentials . Also if you haven't already, one of the requirements is to provide the granting access to the client API within the google admin as shown within the screenshot

The other requirement is to ensure that the authorized access has been assigning the x.apps.googleusercontent.com client as shown within the screenshot also. The full URLs that could be assigned is as follows:
https://www.googleapis.com/auth/admin.directory.group,https://www.googleapis.com/auth/admin.directory.group.member,https://www.googleapis.com/auth/admin.directory.notifications,https://www.googleapis.com/auth/admin.directory.orgunit,https://www.googleapis.com/auth/admin.directory.user,https://www.googleapis.com/auth/admin.directory.user.alias,https://www.googleapis.com/auth/admin.directory.user.security,https://www.googleapis.com/auth/admin.directory.userschema

https://technicalconfessions.com/images/postimages/postimages/_446_5_Assigning the client access for Google OpenIDM.png

Its likely that you've already done all of the above though invalid_grant of the token would imply that google is not authenticating the request. The access token is the OAuth to provide authorized access to a protected resource from the OAuth Authorization Server. These access tokens are short-lived and are often renewed. The refresh token is the token that is used to obtain a new access token.

https://technicalconfessions.com/images/postimages/postimages/_446_6_Creating the client for OAuth Google.png

In OpenIDM terms, the refresh token is stored within the database and it will then use the access tokens to access the google APIs. This occurred when I was attempting to upgrade the connector though by using the same provisioner-* file.

The best approach is to deploy the OOTB provisioner file into the OpenIDM conf directory. Once that has been performed, enter the 'clientSecret' and the 'clientId' into the provisioner.openicf-google.json file. Note that the enabled is set to false at the beginning. Also note that the refrestToken remains as null. This would be populated later once you authenticate using the google app super user. After that, start up OpenIDM. and ensure it starts OK. After that, log in as the admin and click 'connectors'. Then click the connector from disabled to enabled and save. Once that occurs, OpenIDM will then redirect you to the OAuth authorization. Click accept. You will be able to see the provisioner.openicf-google.json file the refreshToken within the configurationProperties section though encrypted.

You should then be able to perform reconcilation once the source and target mapping is complete

Please comment below if this was successful or you don't experience the same outcome

https://technicalconfessions.com/images/postimages/postimages/_446_11_Enable google connector OpenIDM.png

About the author

Daniel is a Technical Manager with over 10 years of consulting expertise in the Identity and Access Management space.
Daniel has built from scratch this blog as well as technicalconfessions.com
Follow Daniel on twitter @nervouswiggles

Comments

Other Posts

ForgeRock IDM - org.forgerock.script.exception.ScriptCompilationException: missing ; before statemen

OpenIDMsync.confForgeRock

September 17, 2017
Created by: Daniel Redfern
ForgeRock IDM - org.forgerock.script.exception.ScriptCompilationException: missing ; before statement
Read More...

Caused by: org.forgerock.json.resource.BadRequestException: Target does not support attribute groups

OpenIDMForgeRockICFConnector

September 17, 2017
Created by: Daniel Redfern
When performing the attempt of a reconciliation from ForgeRock IDM to Active Directory, I would get the following error
Read More...

ForgeRock OpenIDM - InvalidCredentialException: Remote framework key is invalid

OpenIDMForgeRockICFConnectorAD

September 17, 2017
Created by: Daniel Redfern
In the past, the similar error occurred though for the Oracle Identity Management solution. invalidcredentialexception remote framework key is invalid Because they all share the ICF connector framework, the error/solution would be the same.
Read More...

ERROR Caused by com.google.api.client.auth.oauth2.TokenResponseException 400 Bad Request - invalid_g

OpenIDMIDMGoogleGoogle-AppsICFreconciliation

September 12, 2017
Created by: Daniel Redfern
During the reconcilation from OpenIDM to the ICF google apps connector, the following error response would occur. ERROR Caused by com.google.api.client.auth.oauth2.TokenResponseException 400 Bad Request - invalid_grant
Read More...

forgerock-openidm-encryptedjwt-error

OpenIDMIDMForgeRockJWTIAM

August 29, 2017
Created by: Daniel Redfern
Received the JWT error
Read More...

Unexpected character ('¾' (code 190)): expected a valid value

ForgeRock-OpenIDMOpenIDMIDMKeystore

June 25, 2017
Created by: Daniel Redfern
Unexpected character occurred when the IP addresses changes and the virtual instance was migrated into a separate network subnet.
Read More...
E_WARNING Error in file posts.php at line 464: fopen(http://www.technicalconfessions.com/images/postimages/postIcons/pp444.png): failed to open stream: HTTP request failed! HTTP/1.1 404 Not Found E_WARNING Error in file posts.php at line 464: fclose() expects parameter 1 to be resource, boolean given

OpenDJ Error - Connect Error Result Code: 91 (Connect Error)

OpenDJLDAPldapsearchForgeRock

June 5, 2017
Created by: Daniel Redfern
When trying to connect, I would then receive the following error "Connect Error Result Code: 91 (Connect Error)"
Read More...

Tomcat NioEndpoint$SocketProcessor.doRun java.lang.NullPointerException error

TomcatJava-8PKICAS

June 5, 2017
Created by: Daniel Redfern
When initiating the Tomcat instance, the cas-stderr log file will log a SEVERE error logging multiple times every few seconds
Read More...

IDM ERROR - JDBC repository configured but datasource default was not found

ForgeRockIDMJDBC

May 23, 2017
Created by: Daniel Redfern
IDM ERROR - JDBC repository configured but datasource default was not found
Read More...

OpenIDM Issue - javax.crypto.BadPaddingException: Given final block not properly padded

OpenIDMIDMForgeRockcryptography

May 23, 2017
Created by: Daniel Redfern
org.forgerock.json.JsonException: org.forgerock.json.crypto.JsonCryptoException: javax.crypto.BadPaddingException: Given final block not properly padded
Read More...