Obtaining Access Token with curl

I am attempting to create an OAuth2 access token for use by server-side code. I only need to create the access token once, ideally by posting my client ID, key, secret, and scope to some URL. I am going by this procedure [https://api-docs.nightbot.tv/#oauth-2], which does not document that URL. Is this an option, or do I have to 302 web users to your authorization endpoint? There will only be one user of this application (eventually an Amazon Lambda), so the redirect doesn’t make sense for me.

Thanks for your help!

Tim

For server side applications you can use grant_type=client_credentials. There is an example in this following post:

1 Like

Extremely helpful, thank you! Now I am getting the following. Is this equally simple?

$ curl -X GET "https://api.nightbot.tv/1/commands" \
  -H "Authorization: Bearer blahblahblahblah"

{"status":403,"message":"missing required scope"}%                                                                       ~

Yeah you can supply the scope in addition to the other parameters.

curl -X POST \
  https://api.nightbot.tv/oauth2/token \
  -d 'grant_type=client_credentials&client_id=....&client_secret=....&scope=commands%20channel'

and the response will display scopes

{
    "access_token": "....",
    "token_type": "bearer",
    "expires_in": 2592000,
    "refresh_token": "...",
    "scope": "commands channel"
}

as well as the /me endpoint

{
    "status": 200,
    "authorization": {
        ....,
        "scopes": [
            "commands",
            "channel"
        ]
    },
    "user": {....}
}

That works. (I had tried it, but was providing a different scope than the one I was using in the request, hence the…missing required scope. I believe all is well now. Thank you again.)

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