LoginSignup
0
0

More than 1 year has passed since last update.

Auth0 User情報を取得するPowerShellスクリプト

Posted at

下記サイトを参考にしています。1つのスクリプトで実施できるようになったので備忘録として残します。
https://future-architect.github.io/articles/20221130a/

実行環境 Windows Server 2019
PowerShellバージョン 5.1.17763.3770

★スクリプトのコード

$client_id =  "API Explorer Application の Client ID"
$client_secret =  "API Explorer Application の Client Secret"
$api =  "Auth0 Management API のIdentifier(https://ドメイン名.jp.auth0.com/api/v2/)"

$body = @{
    client_id = "$client_id"
    client_secret = "$client_secret"
    audience = "$api"
    grant_type = "client_credentials"
}
$gettoken = Invoke-RestMethod -Method Post -Uri "https://ドメイン名.jp.auth0.com/oauth/token" -ContentType 'application/json' -Body ($body|ConvertTo-Json)
$token = $gettoken.access_token

Invoke-RestMethod -Method Get -Uri "https://ドメイン名.jp.auth0.com/api/v2/users" -Headers @{Authorization="Bearer $token"} >>users.txt

★元記事からの変更点
取得したtokenをoutput.txtに出力するのではなく、変数として取り込み1つのスクリプトで実行できるようにした。
具体的には以下の通り。
・11行目で取得したTokenを変数「gettoken」(適当に命名したもので他の名前でも可)に代入。
・access_token以外にもscope等今回の処理には不要な情報も取れるので、12行目で「access_token」のみを取得し、変数「token 」(これは元記事の変数名そのまま)に代入している。

★11行目で取得されるTokenの内容
{"access_token":"ey(長いので省略)oW40w","scope":"read:client_grants(他多数あり省略)update:client_credentials","expires_in":86400,"token_type":"Bearer"}

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0