# What to do after SAML assertion is returned to service provider?

**URL:** <https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102>\
**Category:** Get Help\
**Tags:** connections, saml-enterprise-connection\
**Created:** [May 23, 2025, 6:45am UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102 "2025-05-23T06:45:29Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![jeremybong](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeremybong/32/70899_2.png) [@jeremybong](https://community.auth0.com/u/jeremybong)\
**Post date:** [May 23, 2025, 6:45am UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/1 "2025-05-23T06:45:29Z")

</div>

Hi all, my team is building a healthcare React application and we are using Auth0 for authentication. We are required to have SAML integration for healthcare institutions.

I have set up the Assertion Consumer Service endpoint in our application. I have set up a Keycloak instance as our internal test IDP. Right now, it is able to receive SAML responses with the assertion from the test IDP.

From here on, I’m not sure what to do next. I have read that I can request an auth token using the SAML assertion. When I try invoking this command:

curl -X POST “/oauth/token” -H “Content-Type: application/x-www-form-urlencoded” -d "grant\_type=urn:ietf:params:oauth:grant-type:saml2-bearer&assertion=\<64 base encoded assertion\>

I get " {“error”:“unauthorized\_client”,“error\_description”:“Grant type ‘urn:ietf:params:oauth:grant-type:saml2-bearer’ not allowed for the client.”,“error\_uri”:“”}"

What am I doing wrong? Thanks!

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [May 27, 2025, 6:38pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/3 "2025-05-27T18:38:44Z")

</div>

Hi @jeremybong,

Welcome to the Auth0 Community and thank you for your post!

> [@jeremybong](#):
>
> I have read that I can request an auth token using the SAML assertion.

Even though what you are specifying here is correct when it comes to standard OAuth 2.0 flows, this is not a standard way of processing SAML assertions in Auth0, so that is why the error mentioned shows up. When the assertion is validated in Auth0, a user session is created right away.

The recommended approach would be using one of our SDK’s, such as the [Auth0-React](https://github.com/auth0/auth0-react) in your use case ( you can check out the documentation [here](https://auth0.github.io/auth0-react/functions/useAuth0.html) ) which handles the SAML response automatically, as well as generating the tokens. Then you can initiate the login using:

```auto
loginWithRedirect({
          connection: "YOUR_SAML_CONNECTION_NAME", 
        })

```

I would also suggest checking this community posts that will better clarify the situation:

- [Using SAML response to get a JWT access token](https://community.auth0.com/t/using-saml-response-to-get-a-jwt-access-token/67746)

- [SAML 2.0 Assertion flow](https://community.auth0.com/t/saml-2-0-assertion-flow/63403)

- [Custom SSO SAML Integration with Auth0 as SP](https://community.auth0.com/t/custom-sso-saml-integration-with-auth0-as-sp/63315)

I hope this helps, so if you have any questions please let me know.  
Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![jeremybong](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeremybong/32/70899_2.png) [@jeremybong](https://community.auth0.com/u/jeremybong)\
**Post date:** [May 27, 2025, 11:10pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/4 "2025-05-27T23:10:02Z")

</div>

Thank you Remus! This was helpful.

Another question. Now I am confused a little by the Assertion Consumer Service endpoint. Is this an endpoint I need to build myself that sits on my app’s backend, or can Auth0 already handle receiving the SAML assertion and redirect back to my app?

Thanks!

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [May 28, 2025, 6:28pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/5 "2025-05-28T18:28:04Z")

</div>

Hi @jeremybong,

Firstly I’m glad this was helpful.

There is also no need for you to create the ACS endpoint in your backend, since consuming the Assertion Process is being done automatically within Auth0 since its role is acting as the Service Provider, being sort of the middleman between your React App and the Idp.

Auth0 will also automatically send the user to your configured Allowed Callback URLs once the authentication is complete on the Idp’s side.

Best regards,  
Remus

---

<div class="post-metadata">

**Author:** ![jeremybong](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/jeremybong/32/70899_2.png) [@jeremybong](https://community.auth0.com/u/jeremybong)\
**Post date:** [May 28, 2025, 7:13pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/6 "2025-05-28T19:13:43Z")

</div>

Thanks Remus, that is also very helpful.

Last question - I have reconfigured our application to callback to /login. After logging into the IDP, which is successful, the browser does successfully redirect to our /login, but then gets stuck in a loop. On the login, we call getAccessTokenSilently first and that fails with “Login required”. It feels like I am missing something because like you said, Auth0 is automatically doing all the redirect work.

 ![Screenshot 2025-05-28 at 12.06.07 PM](https://global.discourse-cdn.com/auth0/original/3X/5/3/53363afac6daf4f0e9a2147115177ae1653a206e.png)

What does the error mean? Thanks!

---

<div class="post-metadata">

**Author:** ![remus.ivan](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/remus.ivan/32/68771_2.png) [@remus.ivan](https://community.auth0.com/u/remus.ivan)\
**Post date:** [May 28, 2025, 10:25pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/7 "2025-05-28T22:25:56Z")

</div>

Hi @jeremybong,

Firstly I would not recommend setting your callback function to your /login, but to the Root URL directly or a simple `/callback` route, since that should be the reason why this is causing a loop in your application. A few details on setting the Callback URL in a React app can be checked using this [community post](https://community.auth0.com/t/callback-url-after-login/106768/3).

The “Login required” error is most likely caused by calling `getAccessTokenSilently` at the wrong moment in time. The SDK might still have to parse the `code` and `state` parameters received from the Idp, so it might not have processed the full authentication flow yet and an unauthenticated session is being returned. I can recommend checking the `isLoading` and `isAuthenticated` functions from the [useAuth0 hook](https://auth0.github.io/auth0-react/functions/useAuth0.html) in the React SDK.

Hope this helps!  
Thanks,  
Remus

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [June 11, 2025, 10:26pm UTC](https://community.auth0.com/t/what-to-do-after-saml-assertion-is-returned-to-service-provider/187102/8 "2025-06-11T22:26:12Z")

</div>

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