Authorization Code Flow - How to retrieve Organization of a User

Hi all,

I would like to integrate web app (Java/Spring Boot) with Okta.
For that I’ve created Okta App (Web) with OpenID.
I’ve add myself as User and Assign myself to this newly created app.
Managed so far to get code (+state) (1st step in Authorization Code Flow) and now I’m exchanging
this code for OpenID Token.

Followed tutorial so far and I’m getting Okta Token back: type, access_token, scope, expires in and id_token.

Claims in id token looks like this:


Now here comes the question …

I need somehow to get info about Organization / Tennant of the Authenticated User. Email/Username is not just enough.

Can someone jumps in and tell me how to obtain that information?

P.S. Integrating with other Auth. providers (e.g. Google, there is a Claim “hd” a.k.a. HOSTED DOMAIN that I could use, or for Microsoft there is “tid” a.k.a. TENANT_ID)

Further more,
I’ve tried to add “Custom Claim”

Went to “API > Authorization Servers” and then edited “default”. Tab “Claims” and I’ve added
Claim. See attached image:

But then when I execute request on:

I’m getting only these info:

“name”:“Aleksandar Stoisavljevic”,

So as you can see no “org_name” claim?

the iss claim will have details about the authorization server and will contain the full URL of the okta org

“iss” claim that is in “id_token” is the one of app itself, right?
In my case, “iss” is “iss”:“".
This one I’m using to communicate to Okta → dev-90739639

But what about other users, I need to get info about their organization, in order to place them to their corresponding tenant.

If it helps, I want to be able to authenticate different users e.g. userA (organization A) and userB (organizationB). I need that organizationX info in order to place userA in Account A and userB in AccountB.

Hope this helps?

Hi @AleksNS,

Id token would have a “idp” claim that will be the Okta org ID or the ID of an Identity Provider if this authentication used Social Authentication or Inbound SAML.

Ref: OpenID Connect & OAuth 2.0 API | Okta Developer

If okta org is not what you are referring to, could you please explain more ? Is this attribute a part of the user’s profile ?

1 Like

Hi @gpadma,

let me try to explain a bit more and afterwards I guess you can give me some idea how to achieve what my goal is.

I have Java/Spring Boot web app that is SaaS solution. For the sake of discussion, let’s say that I have two primary entities: Accounts and Users.
One User (identified by email) will always belong to one Account.

Let’s say that I have following situation of three users:
User1 ( belongs to CompanyA and there is User2 ( also belongs to CompanyA. Please note that domain of email can’t be used as Company identifier.

And let’s say I have 3rd user User 3 ( that belongs to different CompanyB.

Goal is to allow user1 and user2 to use my application (if Okta Authenticate those two users). So if authentication at Okta passes, I need some more information (e.g. organizationName) in order to identify that user (user1 or user2) belongs to CompanyA or in case of user3 belongs to CompanyB.

I’ve started with Authorization Code Flow, created one user (me) and created Okta Application (web). I’m using my Okta user account for testing. I’m able to get back code and state and afterwards (as you can see from examples above) I’m able to get back OpenID token (access_token, id_token, etc.)
Idea that I have is: once User authentication is performed at Okta, I use email/username in order to create that user at my app.

But you can see now, I need one more info → organization, in order somehow to correlate User and Account at my app.

As stated in one of my initial questions, I’ve already implemented integration with Google and Microsoft.
Using Google as auth. server, there is a “hd - hosted domain” claim that I’m using in order to get organization and then I can identify Account based on that info. For Microsoft, similar there is “tid - tenant id” that I’m using for same purpose.

I was hoping that I can use some property of User, e.g. organization (see attached image)

If I can help you with some more info, I’m here to answer any questions that you may have.

Thank You

If the organization value you want in your token is stored in the user’s profile, you will want to configure your claim to use the expression “user.organization” to pull in this value (when present for the user requesting a token).

Hi @andreaskouras,

I finally managed to get “custom” claim of UserInfo.

"name":"Aleksandar Stoisavljevic",

Added “user.organization” as suggested (see image):

Thank You for your help so far.
In case that I have other questions I will feel free to continue this thread.

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.