ExtraBB/open-psd2

CORS error

strootje opened this issue · 3 comments

Hi, not sure if I'm using the client wrong or if ING is doing something wrong but I'm getting the following errors with your client:

Attempt to set a forbidden header was denied: Date
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.sandbox.ing.com/oauth2/token. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://api.sandbox.ing.com/oauth2/token. (Reason: CORS request did not succeed).

I am calling the open-psd2 client from a localhost environment with the following code:

const bank = new ING(true, SigningKey, '<my-super-secret-password>', TlsCert, TlsKey, '<my-client-key>');
bank.requestAccessToken('view_balance').then(console.log, console.error);

I keep getting those CORS errors however. Is there a trick I am missing?

Hi strootje,

Are you running your javascript code from a Node.js server? The following code works for me:

import { ING } from "open-psd2";
const fs = require("fs");

const bank = new ING(true, fs.readFileSync("./secrets/example_client_signing.key"), "changeit", fs.readFileSync("./secrets/example_client_tls.cer"), fs.readFileSync("./secrets/example_client_tls.key"), "example_client_id");

bank.requestAccessToken('view_balance').then(console.log, console.error);

This returns an access token for me. Let me know if you need any help!

I was trying to call the code from a react webapp. Guessing that's impossible then. I was hoping to create an app without a backend.

When I run the code from a Nodejs server everything works as you explained.

Yes that's not possible unfortunately. You could look into using firebase? That's basically a backend for people that don't want a backend.