Hey everyone! I have an issue with integrating goo...
# talk-kratos
l
Hey everyone! I have an issue with integrating google oauth provider into self-hosted Kratos. I make an ajax request to /self-service/login/browser and in response I get the blueprint for a "Sign in with google" button: However there is no URL to redirect to for google auth in the response. Maybe there is a Kratos endpoint for that, but I can't find any mentions in the documentation. Could anyone provide some help? (example response in comments)
{ "action": "http://127.0.0.1:4433/self-service/login?flow=6ed4f791-99f6-4dff-8e8b-be60ae04207e", "method": "POST", "nodes": [ { "type": "input", "group": "oidc", "attributes": { "name": "provider", "type": "submit", "value": "google", "disabled": false, "node_type": "input" }, "messages": [], "meta": { "label": { "id": 1010002, "text": "Sign in with google", "type": "info", "context": { "provider": "google" } } } }, { "type": "input", "group": "default", "attributes": { "name": "csrf_token", "type": "hidden", "value": "KQiptTLvfCseb1EHT8Xc92Ufqww36sFoJGkmjYoYqOpFl1+H1+dauu9M9AnwBi2ZUBpHaB38PKnE2IMhdC+Kfw==", "required": true, "disabled": false, "node_type": "input" }, "messages": [], "meta": {} }, { "type": "input", "group": "default", "attributes": { "name": "identifier", "type": "text", "value": "", "required": true, "disabled": false, "node_type": "input" }, "messages": [], "meta": { "label": { "id": 1070004, "text": "ID", "type": "info" } } }, { "type": "input", "group": "password", "attributes": { "name": "password", "type": "password", "required": true, "autocomplete": "current-password", "disabled": false, "node_type": "input" }, "messages": [], "meta": { "label": { "id": 1070001, "text": "Password", "type": "info" } } }, { "type": "input", "group": "password", "attributes": { "name": "method", "type": "submit", "value": "password", "disabled": false, "node_type": "input" }, "messages": [], "meta": { "label": { "id": 1010001, "text": "Sign in", "type": "info", "context": {} } } } ] }
j
I'm doing this upon sign in with google button is pressed:
Copy code
const onLoginGoogle = () => {
    const data: any = {};
    data[(providerNode!.attributes as any).name] = (
      providerNode!.attributes as any
    ).value;
    data[(csrfTokenNode!.attributes as any).name] = (
      csrfTokenNode!.attributes as any
    ).value;

    return fetch(flow.ui.action, {
      method: flow.ui.method,
      body: new URLSearchParams(data),
      credentials: 'include',
      headers: {
        'Content-Type': 'application/x-www-form-urlencoded',
        Accept: 'application/json',
      },
    })
      .then((r) => r.json())
      .then((r) => router.push(r.redirect_browser_to))
      .catch(errorModal.current?.setError);
  };
l
Thank you for your answer! I have implemented this code, and in the request I send provider: google csrf_token: <......> as url encoded form values, but Kratos responds with status code 422 (Unprocessable Entity) @jolly-tiger-57705 Did you encounter this issue?
j
Nope
Ok, I just got the same error when linking an existing account with google
Turns out 422 contains a valid redirect url 🙂
So just parse the response and redirect and it should be OK
l
Oh yes! Thank you so much! Did not think that the redirect url would be in error body