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

AWS-PHP integration - Email not sent. SMTP Error: Could not authenticate.

phpsmtpaws

February 6, 2020
Created by: Daniel Redfern
AS I was migrating my environment into an S3 environment, I wanted to leverage off the SES services that AWS provide, more specifically, to leverage the off the SMTP functionality by sending an email via PHP
Read More...

SOLUTION: no headers files (.h) found in softwareserial - Arduino

Arduino

February 24, 2019
Created by: Daniel Redfern
The WeMos D1 is a ESP8266 WiFi based board is an extension to the current out-of-the-box library that comes with the Arduino installation. Because of this, you need to import in the libraries as well as acknowledging the specific board. This process is highly confusion with a number of different individuals talking about a number of different ways to integrate.
Read More...

NameID element must be present as part of the Subject in the Response message

ShibbolethSAML

August 7, 2018
Created by: Daniel Redfern
NameID element must be present as part of the Subject in the Response message, please enable it in the IDP configuration.
Read More...

HOW TO provision AD group membership from OpenIDM

OpenIDMICFAD-connector

June 15, 2018
Created by: Daniel Redfern
For what I see, there's not too many supportive documentations out there that will demonstrate how provision AD group membership with the ICF connector using OpenIDM. The use of the special ldapGroups attribute is not explained anywhere in the Integrators guides to to the date of this blog. This quick blog identifies the tasks required to provision AD group membership from OpenIDM to AD using the LDAP ICF connector. However this doesn't really explain what ldapGroups actually does and there's no real worked example of how to go from an Assignment to ldapGroups to an assigned group in AD. I wrote up a wiki article for my own reference: AD group memberships automatically to users This is just my view, others may disagree, but I think the implementation experience could be improved with some more documentation and a more detailed example here.
Read More...

ForgeRock OpenIDM - InvalidCredentialException: Remote framework key is invalid

ICFIDMOpenIDMOpenICF

November 8, 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...

org.forgerock.script.exception.ScriptCompilationException: missing ; before statement

IDMsync.confforgerockopenidm

November 8, 2017
Created by: Daniel Redfern
org.forgerock.script.exception.ScriptCompilationException: missing ; before statement
Read More...

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...