開発者用の OAuth 2.0 との連携
OAuth 2.0 との連携については、以下の情報を参照してください。
設定可能なシステム プロパティ
以下のように、さまざまなシステム プロパティが用意されています。
名前 | キー | 既定値 | 注意 |
---|---|---|---|
Default refresh token duration (デフォルトのリフレッシュ トークン期間) |
| 30 | OAuth 2.0 プロバイダーがトークンを提供しない場合のリフレッシュ トークンの有効期限に設定する日数。 |
Minimum required access token lifetime (最小必須アクセス トークン ライフタイム) |
| 30 | リフレッシュ トークンが利用できない場合のアクセス トークンの最小必須ライフタイム。 |
Max clock skew (最大クロック スキュー) |
| 60 | クライアントと認証サーバー間の最大許容クロック スキュー (秒単位)。このプロパティは、製品クラスター内のノード間の最大クロック スキューとしても使用されます。 |
Max client delay (最大クライアント遅延) |
| 60 | クライアントからの応答の最大許容遅延 (秒単位)。 |
Max server delay (最大サーバー遅延) |
| 60120 | OAuth サーバーからの応答の最大許容遅延 (秒単位)。 |
Minimum lifetime of invalid tokens (無効なトークンの最小ライフタイム) |
| 30 | 無効なトークンがデータベースから削除されるまでの、そのトークンのライフタイムの最小日数。 |
Prune expired tokens schedule (期限切れトークン削除のスケジュール) |
| 0 0 23 * * ? | スケジュールが設定されたトーク削除ジョブの cron 表現。デフォルトは毎日 23:00 です。 |
Default monitor stripe count (デフォルトの監視ストライプ数) |
| 64 | トークンの更新など、フレームワーク全体の同時操作に使用されるストライプのデフォルト数。 |
Skip baseurl https requirement (baseurl https 要件をスキップ) |
| false | Jira インスタンスの baseurl が https であるという要件をスキップするために使用できます (非推奨) |
Skip provider https requirement (provider https 要件をスキップ) |
| false | OAuth 2.0 プロバイダー エンドポイントが https を使用するという要件をスキップするために使用できます (非推奨) |
Unrecoverable token failing period days (回復不能なトークン エラー期間の日数) |
| 7 | エラーが発生しているトークンが回復不能とみなされるまでの最小期間 |
These properties are set on the jira-config.properties
file
Custom values for JIRA's remaining advanced configuration options (i.e. not stored in the JIRA database) are stored as individual key-value pairs in a file called jira-config.properties
(located in the JIRA application home directory). Typically, these options are of little interest to most JIRA system administrators. While these key-value pairs can be edited, JIRA must be restarted for any changed values to take effect.
jira.projectkey.warning = testwarning
jira.projectkey.description = testdescription
...
atlassian.oauth2.client.unrecoverable.token.failing.period.days = 7
In new JIRA installations, this file may not initially exist and if so, needs to be created manually. For more information about editing the
jira-config.properties
file, see Edit the jira-config.properties file in the Jira server.
プラグイン開発者の設定の使用
REST API は、クライアントの設定に関連した CRUD を実行するためだけに提供されています。これは、{{baseurl}}/rest/oauth2-client/latest/config/ URL
で利用できます。
独自の UI を実装する予定がない限り、これらのエンドポイントの大部分は使用する必要がありません。
固有のリクエスト:
GET
リクエストはすべての設定のリストを返します。POST
リクエストは、クライアント設定を本文として持つことで (以下を参照)、新しい設定を保存します。{ "name": "Test client", "description": "Mail handler", "type": "GENERIC", "clientId": "someclientid", "clientSecret": "secretP4ssw0rd", "authorizationEndpoint":"https://authorizationserver.com/oauth2/authorize", "tokenEndpoint": "https://authorizationserver.com/oauth2/token", "scopes": [ "offline_access", "Mail.Read" ], "redirectUriSuffix": "WuBLhHpPAguypjRS7906Jg" }
{{baseurl}}/rest/oauth2-client/latest/config/{{id}}
へのGET
リクエストは、指定された id を持つクライアントの設定を返します。{{baseurl}}/rest/oauth2-client/latest/config/{{id}}
へのDELETE
リクエストは、指定された id を持つクライアントの設定を削除します。{{baseurl}}/rest/oauth2-client/latest/config/{{id}}
へのPUT
リクエストは、指定された id を持つクライアントの設定を更新します。設定は本文で送信する必要があります (フォーマットは上述のPOST
リクエストを参照)。{{baseurl}}/rest/oauth2-client/latest/config/get-redirect-uri?authorizationEndpoint={authEndpoint}
へのGET
リクエストは、特定の認証エンドポイントに生成された一意のリダイレクト URI をクエリ パラメーターとして返します。
添付の postman コレクションを使用すると、API の詳細を確認できます。
プラグイン インターフェース
サードパーティと OAuth 2.0 の接続に役立つさまざまなインターフェースが提供されています。
これらは、Spring Scanner を使用してインポートできます。
ClientConfigStorageService
final ClientConfigurationEntity savedEntity = clientConfigStorageService.save(ClientConfigurationEntity.builder()
.name(---) // (Required)
.providerType(ProviderType.GENERIC) // or ProviderType.MICROSOFT, or ProviderType.GOOGLE (Required)
.description(---) // (Optional)
.clientId(---) // (Required)
.clientSecret(---) // (Required)
.authorizationEndpoint(---) // (Required)
.tokenEndpoint(---) // (Required)
.scopes(---) // (Required)
.build()
);
final ClientConfigurationEntity fetchedEntityById = clientConfigStorageService.getByIdOrFail(savedEntity.getId());
final ClientConfigurationEntity fetchedEntityByName = clientConfigStorageService.getByName(savedEntity.getName());
final List<ClientConfigurationEntity> fetchedEntities = clientConfigStorageService.list();
clientConfigStorageService.delete(savedEntity.getId());
FlowRequestService
final ClientConfigurationEntity clientConfiguration = clientConfigStorageService.getByIdOrFail(id); // id of a saved configuration
final FlowRequest flowRequest = flowRequestService.create(
session, // HttpSession of current request
clientConfiguration,
id -> pluginPage + "/" + id // pluginPage here will describe a landing page after completing the FlowRequest
);
... Complete flow on UI
final FlowResult flowResult = flowRequestService.getFlowRequest(
session, // HttpSession from same user as above
flowRequest.getId()
);
if (flowResult.indicatesSuccess()) { // true if the FlowRequest was successful
final ClientTokenEntity clientToken = clientTokenStorageService.save(
ClientTokenEntity.builder(flowResult.toSuccessResult())
.configId(clientConfiguration.getId()) // config id used above
.build()
);
} else {
final FlowResultError flowResultError = flowResult.toErrorResult();
// Handle FlowResultError...
}
ClientTokenStorageService
final ClientTokenEntity clientToken = clientTokenStorageService.getByIdOrFail(id); // using saved client token id from FlowResult
clientTokenStorageService.save(ClientTokenEntity.builder(clientToken)
.configId(---) // (Required)
.accessToken(---) // (Required)
.accessTokenExpiration(---) // (Required)
.refreshToken(---) // (Required)
.refreshTokenExpiration(---) // (Required)
.build()
);
clientTokenStorageService.delete(clientToken.getId());
TokenHandler
// This will automatically refresh and save the client token if required
final T result = tokenHandler.execute(
clientTokenId, // id of saved client token
clientToken -> // ... execute code that uses token. Can return T.
);
// This will automatically refresh, save, and return the most up to date client token
final ClientToken refreshedToken = tokenHandler.getRefreshedToken(clientTokenId);
TokenService
final ClientTokenEntity clientToken = clientTokenStorageService.getByIdOrFail(clientTokenId);
final ClientConfigurationEntity clientConfiguration = clientConfigStorageService.findByIdOrFail(clientToken.getConfigId());
// Will refresh and return the token. Note this will not save it.
final ClientToken forceRefreshClientToken = tokenService.forceRefresh(clientConfiguration, clientToken);
// Will refresh if the expiry + margin is after the current system time. Note this will not save if refreshed.
final ClientToken marginRefreshClientToken = tokenService.refreshIfNeeded(clientConfiguration, clientToken, Duration.ofDays(1));