How do I get a token for my HTTP API requests?

Hi, I am trying to get a token over the endpoint /auth/realms/{realm}/protocol/openid-connect/token, but I only get:

Screenshot 2023-03-02 at 12-41-26 OpenRemote

Can someone help me please?

Hi,

Did you replace {realm} with the actual realm name? :slight_smile:
Otherwise elaborate a bit further on your setup and attempts to make it work please.

Don

Hi @Don , thanks for your reply!
Oh yes I replaced {realm} with “master”. I posted the wrong screenshot … this is what I get:

Screenshot 2023-03-02 at 13-28-20 OpenRemote

The status is: 405 Method Not Allowed

Any idea how to fix this issue?

Is this an issue from my side or is it an issue of OpenRemote? :slight_smile:

With the use of Postman it works now.

What I have done:

  1. Open Postman and create a new request.
  2. Set the request method zo ‘POST’.
  3. Set the request URL to: https://{your-openremote-url}/auth/realms/{realm}/protocol/openid-connect/token
  4. In the request body, select the x-www-form-urlencoded option and enter the following parameters:
    grant_type: client_credentials
    client_id: {name-of-service-user}
    client_secret: {generated-secret-of-service-user}
  5. Click ‘Send’ to get response with access token

For getting information about a specific asset I did the following:

  1. Create new request in Postman.
  2. Set the request method to ‘GET’.
  3. Set the request URL to: https://{your-openremote-url}/api/master/asset/{assetID} (see also OpenRemote Manager HTTP API Swagger UI)
  4. Add an Authorization header to the request and set the value to Bearer {access_token}, where {access_token} is the access token obtained in the previous step.
  5. Click ‘Send’ button to send the request to OpenRemote.
1 Like

Hi Chief,

Great that you got it to work. Thanks for posting the steps you took! :clap:

Don

1 Like

Hi Chief, I followed all steps: but getting this error, please guide.

Thank you chief,

I stuck in this since long, but after getting your post it become so easy for me, one question, access-token expiring in 1 minute I think, how can we increase time?

Hi faraz, your welcome! Good question. I wrote a Python-script which automatically asks for a new token everytime it gets executed. But how you can change it in another way I do not know unfortunately.

@faraz003: do you fix 401 Unauth error? I meet similar issue like you do. Thanks

Please describe the steps you have tried in your case.

@deputy-chief-hardy gave a brief description on how it should work,
and it should be similar to oAuth2 standards. External use like Postman or use in your own application should use a Service user and the client_credentials grant as described.

Also feel free to open a new topic.

Maybe useful for you: Release: OpenRemote Postman API Collection with fix for OAuth Authentication

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.