in reply to Re: Getting an Access Token
in thread Solved: Getting an Access Token
I'm trying to use the following perl script to request the token. But I get a Bad Request error.POST https://xxx.xx.xx.xx/api/v2/access/token 200 62 ms Warning: Self signed certificate POST /api/v2/access/token HTTP/1.1 Content-Type: application/x-www-form-urlencoded Authorization: Basic bGJLN0dLaGNmVTM2MkxNbjpzOUtKRXR0UVBHeGIyTkxkcEpMM +3hHbmlLN0MwaUk= User-Agent: PostmanRuntime/7.29.0 Accept: */* Cache-Control: no-cache Postman-Token: 1979ab3e-0607-4544-a239-05d37cb2dd87 Host: 172.20.19.21 Accept-Encoding: gzip, deflate, br Connection: keep-alive Content-Length: 29 grant_type=client_credentials HTTP/1.1 200 OK Server: nginx Date: Sat, 05 Mar 2022 07:31:30 GMT Content-Type: application/json; charset=utf-8 Transfer-Encoding: chunked Connection: keep-alive ETag: W/"63-lVO9g4PVOvVMxmtOQ57cFQLhFck" Strict-Transport-Security: max-age=31536000; includeSubDomains Content-Encoding: gzip {"access_token":"16f7a07cc25b2cf3618b8286180eb264744e145f","expires_in +":3600,"token_type":"bearer"}
I get this reponse...#!/usr/bin/perl -w use strict; use warnings; use LWP::UserAgent; my $netloc = "xxx.xx.xx.xx"; my $realm = "Realm"; my $user = "usercode"; my $pass = "passcode"; my $ua = LWP::UserAgent->new(); $ENV{PERL_LWP_SSL_VERIFY_HOSTNAME}=0; $ua->default_header( "Authorization" => "Basic bGJLN0dLaGNmVTM2MkxNbjp +zOUtKRXR0UVBHeGIyTkxkcEpMM3hHbmlLN0MwaUk="); $ua->default_header( "Accept" => "*/*" ); $ua->default_header( "Content-Type" => "application/x-www-form-urlenco +ded"); $ua->credentials( $netloc, $realm, $user, $pass); $ua->ssl_opts( verify_hostname => 0, SSL_verify_mode => 0x00); my $query = "https://".$netloc."/api/v2/access/token"; my $req = HTTP::Request->new( POST => $query); my $resp = $ua->request($req); if ($resp->is_success) { my $output = $resp->decoded_content; print $output."\n"; } else { print $resp->as_string(); }
[user@localhost wifi]$ ./wifi-api-test-token.pl HTTP/1.1 400 Bad Request Connection: close Date: Sat, 05 Mar 2022 07:34:43 GMT ETag: W/"1b-WJVp2bnCdBNm40JHvp3t41llPJs" Server: nginx Content-Length: 27 Content-Type: application/json; charset=utf-8 Client-Date: Sat, 05 Mar 2022 07:35:10 GMT Client-Peer: 172.20.19.21:443 Client-Response-Num: 1 Client-SSL-Cert-Issuer: /O=Cambium Networks Ltd. Client-SSL-Cert-Subject: /O=Cambium Networks Ltd. Client-SSL-Cipher: ECDHE-RSA-AES128-GCM-SHA256 Client-SSL-Socket-Class: IO::Socket::SSL Client-SSL-Version: TLSv1_2 Client-SSL-Warning: Peer certificate not verified Strict-Transport-Security: max-age=31536000; includeSubDomains {"error":"invalid_request"}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Getting an Access Token
by PerlMonger79 (Sexton) on Mar 05, 2022 at 08:14 UTC |