Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[BUG] I get error 400 (Bad Request) in the getOAuthToken function #1

Open
2 of 4 tasks
raikantasahu opened this issue Jul 3, 2024 · 2 comments
Open
2 of 4 tasks

Comments

@raikantasahu
Copy link

Expected Behavior

getOAuthToken should return a valid OAuth token.

Actual Behavior

It throws the following error message:
Warning! Error in getOAuthToken: 400 (Bad Request) from http://localhost/xxxxx/OAuthServer/connect/token

Steps to Reproduce

  1. Enter values in all the fields in the form.
  2. Click on the Submit button

Environment Details

Aras Innovator

  • Major version: 14.0
  • Service pack(s): SP12

Browsers

  • Internet Explorer 11
  • Firefox ESR
  • Chrome
  • Edge

Project Version

v2.0.0

Additional Details

Workaround / Solution

Have you found a workaround or solution to this issue?
No.

Collaboration

Are you willing to collaborate on this feature? Ex: sharing code, submitting a pull request, testing, etc.
Yes.

@gwagner613
Copy link

gwagner613 commented Nov 1, 2024

Had the same issue. Found when using postman app and doing authentication by hand that the Innovator Server (2024) does not like the Content-Type to be multipart/form-data. Seems to only work when it's "application/x-www-form-urlencoded". The getOAuthToken(creds) function sets up the var token_body as a FormData object ... when the http request eventually gets made, that FormData object will cause the Content-Type to be multipart/form-data. Which will faill with Error 400. Fix is to manually set the header and use a string for token_body.

In the getOAuthToken(creds) ... REMOVE:

    // build the OAuth token request
    var token_headers = [];

    var token_body = new FormData();
    token_body.set("grant_type", "password");
    token_body.set("scope", "Innovator");
    token_body.set("client_id", "IOMApp");
    token_body.set("username", creds.user);
    token_body.set("password", creds.pwd);
    token_body.set("database", creds.db);

and REPLACE it with:

    // build the OAuth token request
    var token_headers = [
        { name: 'Content-Type', value: 'application/x-www-form-urlencoded' }
    ];

    // Example URL-encoded token body
    var token_body = 
        "grant_type=password" +
        "&scope=Innovator" +
        "&client_id=IOMApp" +
        "&username=" + encodeURIComponent(creds.user) +
        "&password=" + encodeURIComponent(creds.pwd) +
        "&database=" + encodeURIComponent(creds.db);

Authentication succeeded after that.

@raikantasahu
Copy link
Author

Thanks, @gwagner613
That removed the authentication issue.

Unfortunately, uploading of the selected file fails with the following message:
Warning! 500 (Internal Server Error) from http://localhost/InnovatorServer/vault/odata/vault.CommitTransaction

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants