Hi there - I am trying to find a way to get my SAM...
# gooddata-ui
d
Hi there - I am trying to find a way to get my SAML SSO authentication working on my react app. I noticed the code snippet for SAML SSO login code in your documentation was just updated. I tried running this code snippet, and am getting an error. The code snippet:
Copy code
import sdk from "@gooddata/api-client-bear";

const relayState = "<https://my.app.com/>";

sdk.user
  .initiateSamlSso(relayState)
  .catch(error => {
    // something went wrong, see the browser console for details
    console.error(error);
  });
The error:
Copy code
Error: Cannot parse responseBody.
    at e.getDataInner (xhr.ts:135:19)
    at e.getData (xhr.ts:124:21)
    at user.ts:309:29
Does anyone know why I could be getting this?
j
Hello Daniel, is this maybe because you are using the
<https://my.app.com/>
example domain that does not return parsable responseBody? Where does your analytical application run?
Also, I don't like that the sdk is imported and immediately used without instantiation and any configuration 🤔 The following example looks better to me:
Copy code
import { factory } from "@gooddata/api-client-bear";

const domain = "<https://my.app.com/>";
const sdk = factory({ domain });
This is strange, let me tag @Dan Homola, maybe he'll know more! 🙏
d
Hi Daniel, the snippet you sent looks correct and should work. Can you please check what is in the response body of that network request and what is the HTTP Response code of that request?
d
Hey @Jiri Zajic and @Dan Homola - I got it to work by calling the function through the
backend
, rather than importing
sdk
. See below:
Copy code
import { useBackend } from "@gooddata/sdk-ui";

const backend = useBackend();       

backend?.sdk.user
.initiateSamlSso(URL)
.catch((error: any) => {
    console.error(error);
});
j
Great news @Daniel! @Dan Homola are we still sure that the code snippet without instantiation and configuration of
sdk
is correct?
d
Hi, the
backend?.sdk.user
… call is potentially brittle, the
sdk
prop is marked as private so it might dissappear at any time. It is surprising to me that the default import did not work for you, but what @Jiri Zajic is suggesting might be the correct way after all as it is basically what the sdk-backend-bear does. So please in this case please prefer some form of import directly from the api-client-bear package. Hope this clears things up 🙂
d
Hey @Dan Homola - are you suggesting I instantiate
sdk
like this to be able to successfully call
sdk.user.initiateSamlSso
in a way that will be reliable?
Copy code
import { factory } from "@gooddata/api-client-bear";

const domain = "<https://my.app.com/>";
const sdk = factory({ domain });
d
Hi @Daniel yes that should work well and is a stable API
d
That worked! Thank you @Jiri Zajic & @Dan Homola
👍 1
Sorry @Jiri Zajic and @Dan Homola - I spoke too soon! Using that code also gives me the same
Error: Cannot parse responseBody.
error
d
That is strange 😕 looking trhough the source code, the only thing different that the version that worked for you does compared to the recommended one is stripping the trailing
/
from the domain. Can you please try specifying the domain without th trailing slash?
d
Hey @Dan Homola - removing the trailing
/
from the domain also didn't work. I had a support case open about this if you'd like to see more details about our setup. They recommended we make all of our API requests through the
useBackend()
hook. We were doing our authentication with the Auth0 library originally, which the GoodDataUI SDK didn't seem to support
d
Hi, this is really strange, especially when the backend.sdk version worked 😕 we can try replicating the way the backend.sdk version works. something like:
Copy code
import { factory } from "@gooddata/api-client-bear";

const domain = "<https://my.app.com>";

const sdk = factory();

sdk.config.setCustomDomain(domain);

sdk.user.initiateSamlSso(URL).catch((error: any) => {
    console.error(error);
});
because this is what the
bearFactory
does internally. Can you please try that?