認証

OAuth 2.0 認可コードフローでアクセストークンを取得する

AgriBus API は OAuth 2.0 の 認可コードフロー (OpenID Connect 対応) で認証します。アクセストークンは JWT で、API を呼ぶときは Authorization: Bearer ヘッダーに入れます。

エンドポイントの詳細は 認証サービスのリファレンス を参照してください。

1. 認可リクエスト

ユーザーのブラウザを認可エンドポイントへ誘導します。scope には 必要なスコープ をスペース区切りで指定します。PKCE (code_challenge / code_challenge_method=S256) の利用を推奨します。

https://auth.agribus-connect.net/v1/oauth/authorize
  ?response_type=code
  &client_id=<client_id>
  &redirect_uri=<redirect_uri>
  &scope=openid%20noki.devices.read%20noki.locations.read
  &state=<random>

ユーザーが AgriBus アカウントでログインして許可すると、登録済みの redirect_uri に code と state が付いて戻ります。

2. トークン取得

認可コードをトークンエンドポイントに送ります (application/x-www-form-urlencoded)。

curl -X POST 'https://auth.agribus-connect.net/token' \
  -d 'grant_type=authorization_code' \
  -d 'code=<code>' \
  -d 'redirect_uri=<redirect_uri>' \
  -d 'client_id=<client_id>' \
  -d 'client_secret=<client_secret>'

レスポンスは TokenResponse です。accessToken と有効期限 accessTokenExpiredAt、更新用の refreshToken が返ります。

3. トークンの更新

有効期限が切れたら grant_type=refresh_token で更新します。

curl -X POST 'https://auth.agribus-connect.net/token' \
  -d 'grant_type=refresh_token' \
  -d 'refresh_token=<refresh_token>' \
  -d 'client_id=<client_id>' \
  -d 'client_secret=<client_secret>'

4. API を呼ぶ

curl 'https://datastore.agribus-connect.net/v1/agricultural-machinery/devices' \
  -H 'Authorization: Bearer <accessToken>'
  • トークンが無い、または不正なら 401
  • トークンに必要なスコープが含まれていなければ 403

OpenID Connect

scope に openid を含めると ID トークンを扱えます。ユーザー情報は /v1/oidc/userinfo、署名検証用の公開鍵は /.well-known/jwks.json から取得できます。

2026-10-27 時点の本番サーバーの OpenAPI から生成