OnPremise - API Refresh Token

  • 1
  • Question
  • Updated 1 year ago
Hello,
I'm on HiveManagerNG OnPremise, version 11.14.0.2.

Few weeks ago, I have spent some times to write script which allow supervision of our APs through Nagios with the very useful API.
Since, everythings worked like a charm, but this morning I have an authentication problem caused by the expiration of my token.

Is there a way to automatically refresh tokens in the script.
I found URL like below for cloud solution, but nothing for onpromise one. https://cloud.aerohive.com/services/oauth2/token?grant_type=refresh_token&refresh_token=XXX

Have you any ideas ?
Thank you.

Anthony
Photo of Anthony

Anthony

  • 1 Post
  • 0 Reply Likes

Posted 1 year ago

  • 1
Photo of Jonas Dekkers

Jonas Dekkers

  • 152 Posts
  • 29 Reply Likes
Yet it is possible. I use the below code (php):

$request = new HttpRequest();
        $request->setUrl('https://cloud.aerohive.com/services/oauth2/token');
        $request->setMethod(HTTP_METH_POST);

        $request->setQueryData(array(
          'grant_type' => 'refresh_token',
          'redirect_uri' => "$web_url",
          'client_id' => "$client_id",
          'client_secret' => "$client_secret",
          'refresh_token' => "$refreshtoken"
        ));

        $request->setHeaders(array(

          'content-type' => 'application/x-www-form-urlencoded',
          'refresh_token' => "$refreshtoken",
          'client_secret' => "$client_secret",
          'client_id' => "$client_id",
          'redirect_uri' => "$web_url",
          'grant_type' => 'refresh_token'
        ));

        $request->setContentType('application/x-www-form-urlencoded');
        $request->setPostFields(array(
          '' => ''
        ));

        try {
          $response = $request->send();

          //echo $response->getBody();
        } catch (HttpException $ex) {
          echo $ex;
        }
Photo of Jonas Dekkers

Jonas Dekkers

  • 152 Posts
  • 29 Reply Likes
I didn't see that you mentioned On Premise. I don't know if this code is working for on premises