Create a Identity with ORY hosted and console, CORS issue (kratos)

520 Views Asked by At

I am using Ory kratos's API and sdk, I can not seem to get any data back from my admin console or my hosted kratos, I am getting a cors error(This also happens when the server is off)

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://ory.project.oryapis.com/admin/identities. (Reason: CORS request did not succeed). Status code: (null).

I have tried everything it seems, I had a look through the console and no cors needed to be changed or set, and insomnia can create and get data from the same API and the hosted version, so I am thinking its my code(NOTE I am using axios) but I also can see anything wrong with it.

const axiosClient = axios.create({
  headers: { 
    'Content-type': 'application/json' 
  },
  withCredentials: true
});

export async function createIdentity(email) {
  try {
    const { data } = await axiosClient.post('http://127.0.0.1:4434/identities', {
        traits: {
          email: email
      }
    });

    console.log(data);
  } catch (error) {
    console.log(error);
  }
}

insomnia working insomnia working

I also tryed the SDK and got the same thing

const identity = new IdentityApi(
  new Configuration({
    basePath: `https://pedantic.projects.oryapis.com`,
    accessToken: 'Bearer My_token',
    baseOptions: {
      withCredentials: true
    }
  })
);

export async function createIdentity(email: string) {
  return await identity
    .createIdentity({
      createIdentityBody: {
        schema_id: 'preset://email',
        traits: {
          email: email
        }
      }
    })
    .then(({ data }) => data);
}

I also tried it locally and got the same thing, my kratos(v0.11.0) config

serve:
  public:
    base_url: http://127.0.0.1:4433/
    host: 127.0.0.1
    cors:
      enabled: true
      allowed_origins:
        - 'http://localhost:5000'
        - 'http://localhost:3000'
      allowed_methods:
        - POST
        - GET
        - PUT
        - PATCH
        - DELETE
      allowed_headers:
        - Authorization
        - Access-Control-Allow-Origin
        - Cookie
        - Content-Type
      exposed_headers:
        - Content-Type
        - Set-Cookie
  admin:
    base_url: http://kratos:4434/
    host: 127.0.0.1

But everything is working fine on insomnia

LOGS:

INFO[2022-12-20T15:47:41+10:00] completed handling request http_request=map[headers:map[accept:*/* accept-encoding:gzip, deflate, br accept-language:en-US,en;q=0.5 access-control-request-headers:content-type access-control-request-method:POST connection:keep-alive origin:http://127.0.0.1:5000 referer:http://127.0.0.1:5000/ sec-fetch-dest:empty sec-fetch-mode:cors sec-fetch-site:same-site user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:108.0) Gecko/20100101 Firefox/108.0] host:127.0.0.1:4434 method:OPTIONS path:/admin/identities query:<nil> remote:127.0.0.1:38972 scheme:http] http_response=map[headers:map[location:/admin/identities] size:0 status:307 text_status:Temporary Redirect took:100.3µs]

0

There are 0 best solutions below