Thanks for reaching out to me.
Since yesterday - I was trying to find a solution for this problem. I got little success with connecting from MongoDB compass but not from mongosh ( Ubuntu host )
When i used curl to find out what access token I was getting - from Keycloak - I found out that there were 2 audience values were reported - mongodb-client ( which I wanted ) and also account. While trying to research this - I found out from web - on how to remove the account (audience default value).
Once I was able to fix that - I got these values for Keycloak ( modifed for viewing here )
{
“exp”: 1782496554,
“iat”: 1782496254,
“jti”: “2e61e825-9032-41e2-9bf7-65e72219e510”,
“iss”: “realms/Mongodb",
“aud”: “mongodb-client”,
“sub”: “myemailaddress",
“typ”: “Bearer”,
“azp”: “mongodb-client”,
“sid”: “d6168019-b043-402b-b729-53b1e197675c”,
“acr”: “1”,
“scope”: “profile email”,
“email_verified”: true,
“name”: “myname”,
“preferred_username”: “myemailaddress",
“given_name”: “my first name”,
“MyClaim”: [
“/database_admin”
],
“family_name”: “my last name”,
“email”: “myemailaddress"
}
My mongodb OIDC values in mongod.conf
setParameter:
authenticationMechanisms: MONGODB-OIDC, PLAIN, SCRAM-SHA-1, SCRAM-SHA-256
oidcIdentityProviders: ‘[ {
issuer: "”realms/Mongodb,
clientId: “mongodb-client”,
audience: “mongodb-client”,
authNamePrefix: “keycloak”,
principalName: “preferred_username”,
useAuthorizationClaim: true,
supportsHumanFlows: true,
authorizationClaim: “MyClaim”
} ]’
MongoDB Compass - some of the setting needed - direct access / redirect address / trusted host / host were the instance is running etc.
Later - MongoDB Compass is able to connect to MongoDB instance
on the Ubuntu host - mongosh fails still - even when MongoDB compass works.
error reported -
Error: Unable to fetch issuer metadata for “realms/Mongodb": something went wrong (caused by: The operation was aborted.)
in mongodb log
“error”:“AuthenticationAbandoned: Authentication session abandoned, client has likely disconnected”