0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

サーバー側からZoom会議を作成する-3:リフレッシュトークンとアクセストークンの取得

Posted at

概要

  • 前回の記事の続きです
  • 認証コード、Clint ID、Client Secret、リダイレクトURLを指定して、リフレッシュトークン、アクセストークンなどを取得します
  • 結果はJSONで返ってくるので、WEBブラウザ以外にプログラムでも受け取ることができます
    • 利用者が画面で関与する必要がありません

2つのトークン

  • アクセストークン
    • 会議の作成などに使う
    • 約3600秒(=1時間)で有効期限が切れる
  • リフレッシュトークン
    • アクセストークンを新たに生成するのに使う
    • 長さは不明だが、有効期限がある
    • アクセストークン生成時に、リフレッシュトークンも変わるので、忘れずに保存する

トークンの取得方法

  • 以下の形式で送信すると、レスポンスのJSONに含まれている
curl -X POST https://zoom.us/oauth/token \
  -H "Authorization: Basic BASE64_ENCODED_CLIENT_ID_AND_SECRET" \
  -H "Content-Type: application/x-www-form-urlencoded" \
  -d "grant_type=authorization_code&code=AUTHORIZATION_CODE&redirect_uri=YOUR_REDIRECT_URI"

BASIC認証

  • Client IDとClient Secretを「:」で連結して、BASE64エンコードする
    • 例:Client IDが「123」、Client Secretが「abc」の場合
      • コマンドラインでは、echo "123:abc" | base64
      • JavaScriptではこんな感じ
function encodeBase64(clientID, clientSecret) {
  const credentials = clientID + ':' + clientSecret;
  const encodedCredentials = Buffer.from(credentials).toString('base64');
  return encodedCredentials;
}

認証コード (Authorization code)

  • 前回の記事 で取得したもの
  • 数分で期限が切れるようなので注意

リダイレクトURI

  • 前回の記事 で、認証コードを受けとるために指定したリダイレクトURIを使う
  • アプリ作成時にZoom App Marketplaceで指定したものと同じにする必要がある

戻り値の例

{
	"access_token": "eyJzd(中略)LRa0g",
	"token_type": "bearer",
	"refresh_token": "eyJzd(中略)Ps0HQ",
	"expires_in": 3599,
	"scope": "meeting:write:meeting:admin meeting:write:meeting:master meeting:write:invite_links:master",
	"api_url": "https://api.zoom.us"
}

トークンの保存

  • アクセストークン、アクセストークンの有効期限(現在から1時間後)、リフレッシュトークンは、後で使うので保存しておきます

よくあるエラーと確認事項

{
  "reason":"unsupported grant type",
  "error":"unsupported_grant_type"
}
  • 認証コードの期限が切れていないか?

次回

  • 次回は、アクセストークンを使って会議を作成します
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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?