How is your experience with the OutSystems Community?
85
Views
12
Comments
Solved
Get odc token from session

Bonjour,

I have a question about tokens. I have connected my application to the Keycloak of my company with  identity provider, and it's working fine.

In my company, we have an API , and I would like to use it. The API is protected with Keycloak as well, and calls need a token.

Is it possible to get the current refresh token use by ODC so I can access Keycloak to call the API?

2024-04-23 10-08-23
Vincent Massieye
Solution

How to get the token with Keycloak:

  1. First, I connected Keycloak as an identity provider in ODC.
  2. On exception, if no user is logged in, I redirect to the Keycloak authentication page with a redirection to a custom page afterward.
  3. The custom page will receive the token from Keycloak. I send this token to the Keycloak API to obtain a refresh token and store it in a database.
  4. After that, Keycloak acts as an SSO, so ODC reloads with the authenticated user.

Later, if I need to call my API, I use the refresh token to obtain a new access token.

UserImage.jpg
Luís Matos

Hey Vincent, question, how does the custom page receive the token? Just add the input for the screen?

2024-04-23 10-08-23
Vincent Massieye

Hi Luis,

Yes, I had a code input with parameters.



Vincent


UserImage.jpg
Luís Matos

Thanks!

I tried this but didn't work for me. Maybe it simply doesn't work with entra?

Can you run me through what you did?


I'm doing the usual


The redirect URL is this Request_AbsoluteURL("/MyModule/LandingPage")

And then the redirect page is this:


Do I need to had the?code= to the redirect URL?


Cheers,

Luís

2024-04-23 10-08-23
Vincent Massieye

I have a Keycloak template under review in the forge.

Is your landing page called by the Keycloak redirect URL?

UserImage.jpg
Luís Matos

I'm using OpenId Connect to Entra\Azure AD
Maybe that one works differently.


Cheers,

Luís Matos

2026-09-23 05-49-35
Aayush Shrivastava

Hey @Vincent Massieye ,

For getting the refresh token you have to use system event handler OnApplicationResume.

where you can write a code to get a new fresh token.



Kind regards 
Aayush Shrivastava

2024-04-23 10-08-23
Vincent Massieye

Thank you for the answer, but it's not really what I'm looking for. I probably didn't explain my problem very well. However, I discovered this feature thanks to you. 

2021-10-09 07-57-44
Stefan Weber
 
MVP

Hi Vincent,

the short answer is no (sorry). The original identity and access tokens from your keycloak instance are only used to authenticate a user with the odc identity management solution. The latter then issues its own identity and access token and there is no way to retrieve the brokered ones.

Stefan

2024-04-23 10-08-23
Vincent Massieye

Thanks, I finally made a custom connection before the ODC connection where I get a token and store the refresh token in a database. 


2024-04-23 10-08-23
Vincent Massieye
Solution

How to get the token with Keycloak:

  1. First, I connected Keycloak as an identity provider in ODC.
  2. On exception, if no user is logged in, I redirect to the Keycloak authentication page with a redirection to a custom page afterward.
  3. The custom page will receive the token from Keycloak. I send this token to the Keycloak API to obtain a refresh token and store it in a database.
  4. After that, Keycloak acts as an SSO, so ODC reloads with the authenticated user.

Later, if I need to call my API, I use the refresh token to obtain a new access token.

UserImage.jpg
Luís Matos

Hey Vincent, question, how does the custom page receive the token? Just add the input for the screen?

2024-04-23 10-08-23
Vincent Massieye

Hi Luis,

Yes, I had a code input with parameters.



Vincent


UserImage.jpg
Luís Matos

Thanks!

I tried this but didn't work for me. Maybe it simply doesn't work with entra?

Can you run me through what you did?


I'm doing the usual


The redirect URL is this Request_AbsoluteURL("/MyModule/LandingPage")

And then the redirect page is this:


Do I need to had the?code= to the redirect URL?


Cheers,

Luís

2024-04-23 10-08-23
Vincent Massieye

I have a Keycloak template under review in the forge.

Is your landing page called by the Keycloak redirect URL?

UserImage.jpg
Luís Matos

I'm using OpenId Connect to Entra\Azure AD
Maybe that one works differently.


Cheers,

Luís Matos

2026-01-18 14-14-39
Alexander Ng

hi @Vincent Massieye , can you clarify more what you did. Because I believe the authorization code will be consumed by OIDC in order to create a user's session so there will be no code return to callback screen. Thank you.

2024-04-23 10-08-23
Vincent Massieye

Hi,

The process I use has two steps.

First, I use the OutSystems External Logic to connect to the SSO (Keycloak). 

Then, I check whether a refresh token is already stored in a database. If not, I redirect the user to the SSO to request a token. The SSO returns the token as a parameter, I store it in the database, and then redirect the user back to the application.

Community GuidelinesBe kind and respectful, give credit to the original source of content, and search for duplicates before posting.