cancel
Showing results for 
Search instead for 
Did you mean: 
cancel
3910
Views
5
Helpful
0
Replies

Using PowerShell to Generate an OAuth Token for Cisco API Console

Tim Glen
Cisco Employee
Cisco Employee

I know there are examples of how to Gen an OAuth token in Python & CURL but I like using PowerShell so here is a script I wrote to generate an OAuth Token. 

1: Access the Cisco API console at https://apiconsole.cisco.com

2: Login with your CCO credentials (login is only available to registered Cisco customers and partners).

3: Register your application and obtain your client credentials.

4: Once you register your application and obtain your client ID and client secret, the next step is to obtain an authorization token. Authorization tokens in the Cisco PSIRT openVuln API are valid for one (1) hour.  The Powershell script below will tell the API service to grant you an access_token.

# Clear all Used Variables

$url=''

$postdata=''

$content=''

$auth_response=''

$url='https://cloudsso.cisco.com/as/token.oauth2'

$postdata= @{client_id='INSERT_YOUR_CLIENT_ID';client_secret='INSERT_YOUR_CLIENT_SECRET';grant_type='client_credentials'}

$content='application/x-www-form-urlencoded'

$auth_response=Invoke-RestMethod -URI $url -Method Post -Body $postdata -ContentType $content

Write-Host $auth_response

The response should look like this.

response.jpg

Be sure to note the access_token you received!    You will need it in subsequent queries.

Also be sure to remember that this access_token is ONLY valid for one hour.

Please comment and rate this post!   Thanks

0 Replies 0