Extension:OAuth

From mediawiki.org
This page is a translated version of the page Extension:OAuth and the translation is 70% complete.
Outdated translations are marked like this.
混同しないでください: Extension:OATHAuthまたは Extension:WSOAuth.
MediaWiki 拡張機能マニュアル
OAuth
リリースの状態: 安定
実装 利用者識別 , 利用者権限 , API
説明 利用者が自分の代わりに MediaWiki 操作 API を使用する別のアプリケーション ("consumer") を安全に認可できるようにする。
作者 Aaron Schulz, Chris Steipp, Brad Jorsch, Robert Vogel, Dejan Savuljesku
最新バージョン 1.1.0 (continuous updates)
互換性の方針 MediaWiki とともにリリースされるスナップショット。 master には後方互換性がありません。
MediaWiki >= 1.42
データベースの変更 はい
Composer mediawiki/oauth
テーブル oauth_accepted_consumer
oauth_registered_consumer
ライセンス GNU 一般公衆利用許諾書 2.0 以降
ダウンロード
ヘルプ Help:OAuth
  • $wgOAuth2PublicKey
  • $wgOAuth2RequireCodeChallengeForPublicClients
  • $wgMWOAuthCentralWiki
  • $wgMWOAuthSecureTokenTransfer
  • $wgMWOAuthSharedUserSource
  • $wgOAuth2GrantExpirationInterval
  • $wgOAuthAutoApprove
  • $wgMWOauthDisabledApiModules
  • $wgOAuth2EnabledGrantTypes
  • $wgMWOAuthNonceCacheType
  • $wgOAuthGroupsToNotify
  • $wgMWOAuthRequestExpirationAge
  • $wgOAuth2RefreshTokenTTL
  • $wgMWOAuthSessionCacheType
  • $wgMWOAuthReadOnly
  • $wgOAuth2PrivateKey
  • $wgMWOAuthSharedUserIDs
  • $wgOAuthSecretKey

  • mwoauthproposeconsumer
  • mwoauthupdateownconsumer
  • mwoauthmanageconsumer
  • mwoauthsuppress
  • mwoauthviewsuppressed
  • mwoauthviewprivate
  • mwoauthmanagemygrants
Quarterly downloads 93 (Ranked 62nd)
Public wikis using 982 (Ranked 246th)
translatewiki.net で翻訳を利用できる場合は、OAuth 拡張機能の翻訳にご協力ください
Vagrant role oauth
問題点 未解決のタスク · バグを報告

OAuth 拡張機能が実装するMediaWikiのOAuthサーバは、プロトコル版番号 OAuth 1.0aOAuth 2.0 の両方に対応しています。 これによりサードパーティの開発者はアプリケーション (「消費者」) を安全に開発でき、利用者は付与する権限一式 (「承諾」) を限定できるため、利用者に代わってそのアプリケーションに MediaWiki 操作 API を使用させます。

OAuth を特定のウィキで使用するアプリケーション開発を検討中なら、開発者向け OAuth 解説をご参照ください。 この拡張機能がインストールされているウィキでOAuth対応のツールを使おうとしている場合は、OAuth を参照してください。

要件

  • OAuthは一時的なトークンとセッションのためにオブジェクトキャッシュに依存しています。 キャッシュ構成設定がまともな限り、うまくいくはずです。 (Older versions required Memcached explicitly.)
  • 現在、MySQLとSQLiteのデータベースバックエンドのみをサポートしています。
  • MediaWiki のインストールがプライベートの場合(利用者は必ずログインして閲覧許可を得る場合)、Special:OAuthをホワイトリストに加筆して対応できるかもしれません。

インストール


Vagrantでのインストール:

  • Vagrant を使用している場合は、vagrant roles enable oauth --provisionでインストールしてください。

To assign a permission to some group, for example to sysops, you add following line to LocalSettings.php:

$wgGroupPermissions['sysop']['mwoauthproposeconsumer'] = true;

設定

パラメーター

変数名 既定値 説明
$wgMWOAuthCentralWiki false Wiki ID of OAuth management wiki. On wiki farms, it makes sense to set this to a wiki that acts as a portal site, is dedicated to management, or just handles login/authentication. It can, however, be set to any wiki in the farm. For single-wiki sites or farms where each wiki manages consumers separately, it should be left as false.
$wgMWOAuthSharedUserIDs false (廃止予定) 代わりに $wgMWOAuthSharedUserSource を使用

Whether shared global user IDs are stored in the oauth tables. ウィキファームのうち単一の OAuth 管理ウィキを共有する CAS(中央認証システム)を採用する場合 (整数の利用者 ID) は、必ず true に設定。 If wikis have a central authentication system but have their own OAuth management, then this can be either true or false. Otherwise it should always be set to false. これを true に設定する条件として、 CentralIdLookup またはいずれかの MWOAuth が対応する承諾拡張機能が必須です。 This value should not be changed after the fact to avoid ambigious IDs. Proper user ID migration should be done before any such changes.

$wgMWOAuthSharedUserSource null Central ID provider when sharing OAuth credentials over a wiki farm

Source of shared user IDs, if enabled. If CentralIdLookup is available, this is the $providerId for CentralIdLookup::factory(). Generally null would be what you want, to use the default provider. If that class is not available or the named provider is not found, this is passed to the OAuthGetUserNamesFromCentralIds, OAuthGetLocalUserFromCentralId, OAuthGetCentralIdFromLocalUser, OAuthGetCentralIdFromUserName hooks. $wgMWOAuthSharedUserIDs を false に設定してあると、無効。

$wgMWOAuthRequestExpirationAge 2,592,000 (30 days) Seconds after which an idle request for a new Consumer is marked as "expired"
$wgMWOAuthSecureTokenTransfer true Require SSL/TLS for returning Consumer and user secrets. これは RFC 5849 により必須とされますが、OAuth を使いたいウィキが SSL に対応していない場合は、この設定をオプションで有効にできます。 ほとんどの製品の設定では、必ず trueに設定。
$wgOAuthSecretKey $wgSecretKey A secret configuration string (random 32-bit string generated using "base64_encode(random_bytes(32))") used to hmac the database-stored secret to produce the shared secrets for Consumers. This provides some protection against an attacker reading the values out of the consumer table (the attacker would also need $wgOAuthSecretKey to generate valid secrets), and some protection against potential weaknesses in the secret generation. この文字列が侵害された場合、サイトは必ず新しい $wgOAuthSecretKey を生成して、コンシューマ認証のうち公開鍵/秘密鍵をHMAC/共有秘密署名で代用するものを無効にしてください。 Consumers can regenerate their new shared secret by using the "Reset the secret key to a new value" option under Special:MWOAuthConsumerRegistration/update. If null, the value is set to $wgSecretKey.
$wgOAuthGroupsToNotify [] The list of user groups which should be notified about new consumer proposals. Setting this will only have an effect when Echo is installed.
$wgMWOauthDisabledApiModules [] List of API module classes to disable when OAuth is used for the request
$wgMWOAuthReadOnly false Prevent write activity to the database. When this is set, consumers cannot be added or updated, and new authorizations are prohibited. Authorization headers for existing authorizations will continue to work. Useful for migrating database tables
$wgMWOAuthSessionCacheType $wgSessionCacheType The storage mechanism for session data. If null, it defaults to $wgSessionCacheType.
$wgOAuthAutoApprove [] Allows automatic immediate approval of low-risk apps. In the form of [ 'grants' => [ 'grant1', 'grant2', ... ] ]
$wgOAuth2EnabledGrantTypes
[
"authorization_code",
"refresh_token",
"client_credentials"
]
OAuth2 承諾の一覧のうち、クライアント・アプリケーションの使用が許可されたもの。 実態の承諾クライアント・アプリケーションは、ここに示した承諾のどれでも採用できます。 Grants, other than the ones listed here, are considered legacy grants, and are not supported by this extension
$wgOAuth2PrivateKey "" Private key or a path to the private key used to sign OAuth2 JWT being transmitted. See the OAuth 2.0 Server documentation for how to generate the keys.
$wgOAuth2PublicKey "" Public key or a path to the public key used to verify OAuth2 resource requests.
$wgOAuth2RequireCodeChallengeForPublicClients true OAuth2 のリクエスト時にクライアントから送るコードチャレンジが必須かどうかコントロール 対象となるのは非機密型のクライアントのみです。
$wgOAuth2GrantExpirationInterval "PT1H" (1 hour) Controls validity period for access tokens (stored in the cache configured in MWOAuthSessionCacheType). オーナー限定のクライアントは対象外で、理由はオーナーのアクセストークンは常に期限がないけら ISO 8601 有効期限もしくは無期限のトークンの場合は "infinity" または false のどちらかに設定。
$wgOAuth2RefreshTokenTTL "P1M" (1 month) Controls validity period for refresh tokens (stored in the cache configured in MWOAuthSessionCacheType). ISO 8601 有効期限もしくは無期限のトークンの場合は "infinity" または false のどちらかに設定。

利用者権限

権限 説明
mwoauthproposeconsumer 新しいコンシューマーを提案
mwoauthupdateownconsumer 自身が制御できるOAuthコンシューマーを更新
mwoauthmanageconsumer OAuthコンシューマーを管理
mwoauthsuppress OAuthコンシューマーを秘匿
mwoauthviewsuppressed 秘匿されたOAuthコンシューマーを閲覧
mwoauthviewprivate 非公開OAuthデータを閲覧
mwoauthmanagemygrants OAuth付与を管理

エンドポイント

OAuth 2.0 REST エンドポイント

The following REST endpoints are provided for OAuth 2.0 interaction

パス 説明 許容されるパラメーター Allowed method
/oauth2/authorize Used for retrieving authorization code when using authorization_code grant.
名前 必須かどうか 説明
response_type はい
client_id はい
redirect_uri いいえ これがあるとクライアントの登録時に送信した URI とまったく同一でなければなりません
scope いいえ
state いいえ
code_challenge いいえ $wgOAuth2RequireCodeChallengeForPublicClientstrue の場合に必須
code_challenge_method いいえ $wgOAuth2RequireCodeChallengeForPublicClientstrue の場合に必須
GET
/oauth2/access_token Used for requesting access tokens
名前 必須かどうか 説明
grant_type はい type of grant used
client_id いいえ
client_secret いいえ クライアントが confidential の場合に必須
redirect_uri いいえ これがあるとクライアントの登録時に送信した URI とまったく同一でなければなりません
scope いいえ
code いいえ authorization_code 承諾の採用に必須
refresh_token いいえ refresh_token 承諾の採用に必須
code_verifier いいえ
POST
/oauth2/resource/{{type}} 前に発行したアクセストークンを採用して、保護されたリソースの取得に使います。

現状でこのエンドポイントから取得できるリソースは2樹類あり、{{type}} プレースフォルダを以下のタイプキーに切り替えます。

  • profile - 利用者のプロファイルを取得するとき、リクエストに採用するアクセストークン - 通常は MediaWiki を使う利用者がサードパーティの Web サイトへのログイン時に適用するものを使い、それに対応する利用者を対象とします。
  • scopes - すべてのスコープのクライアント(アプリケーション)取得は現在のアクセストークンと併用できる
パラメータは使えず、唯一の例外はパスに含まれる {{type}} パラメータ GET/POST
/oauth2/client ログイン利用者について OAuth 1.0a または 2.0 クライアントを一覧にします。 認証は CentralAuth 経由、または認証ヘッダにアクセス・トークンを書き込んでも実施します。
レスポンスの例
{
  "clients": [
    {
      "client_key": "xxxxxxxxxxxxxx",
      "name": "TestFromCurl1807",
      "version": "2.0",
      "email": "admin@example.com",
      "callback_url": "http://example.com",
      "scopes": [
        "authonly"
      ],
      "registration": "20200818230806",
      "stage": 0,
      "oauth_version": 2,
      "description": "foo",
      "allowed_grants": [
        "authorization_code"
      ],
      "registration_formatted": "23:08, 18 August 2020"
    }
  ],
  "total": 1
}
  • oauth_version (省略可能) - 設定値は1(戻し値は OAuth 1.0a クライアント限定)または 2(戻し値は OAuth 2.0 クライアント限定)。 既定値: 2
  • Pagination parameters
    • limit (省略可能) - 返すクライアント件数の上限値。 既定値: 25
    • offset (省略可能) - 最初の結果を返す前にスキップするクライアントの件数。 既定値: 0
GET
/oauth2/client/{client_key}/reset_secret クライアントのシークレットをリセット。 オーナー限定のクライアントの場合、 このエンドポイントはアクセストークンもリセットします。
レスポンスの例
{
  "name": "Example",
  "client_key": "xxxxxxxxxx",
  "secret": "xxxxxxxxxx",
  "access_token": "xxxxxxxxxx"
}
名前 必須かどうか 説明 既定
client_key はい クライアントの識別子
reason いいえ シークレットをリセットする理由を述べた文字列。 ''
POST
/oauth2/client OAuth 2.0 クライアントを作成。
レスポンスの例
{
  "name": "Example",
  "client_key": "xxxxxxxxxx",
  "secret": "xxxxxxxxxx",
  "access_token": "xxxxxxxxxx"
}
名前 必須かどうか 説明 既定
name はい クライアントの名称
description はい クライアントの説明
email はい 問い合わせ先のメールアドレス
is_confidential はい クライアントが機密保持型の場合は true に設定、モバイルやデスクトップアプリなど公開クライアントは false に設定
grant_types はい クライアントが適用する OAuth 2.0 承諾の種別 は以下のうちの1件または複数です。 authorization_code, refresh_token, client_credentials
scopes はい OAuth 2.0 の適用範囲はmwoauth-authonlymwoauth-authonlyprivate もしくは適用する承諾の一式のいずれか
version いいえ クライアントのバージョン。 1.0
wiki いいえ 対応するプロジェクト。 * は全てのウィキに対応
owner_only ? true に設定、作成者である利用者しか使わないクライアントに限定
callback_url いいえ 権限のある利用者に URL を返します。 ''
callback_is_prefix いいえ true に設定、クライアントが リクエストのコールバック確認と必須の前置詞としてコールバック URL を使えるようにします。 false
POST
OAuth 資格情報を特定のウィキファーム上で共有する場合は、すべてのウィキで実名が一貫して使用/非表示にしてあるかどうか確認してください($wgHiddenPrefs を使用)。 実名が隠されているウィキでは、どの情報が共有されるかを伝えるOAuth許可要求メッセージは実名に言及しないので、その場合、OAuth消費者がまだその情報を取得できる他のウィキが存在しないはずです。

実験用RESTエンドポイント

実験的なRESTエンドポイントを有効にするには、$wgRestAPIAdditionalRouteFiles 設定変数をLocalSettings.phpに追加してください。

$wgRestAPIAdditionalRouteFiles[] = "$wgExtensionDirectory/OAuth/experimentalRoutes.json";

関連項目

  • Extension:OATHAuth - 名称が似た拡張機能で、OATH-基準のワンタイムパスワードを使う二次的な認証ファクタを採用します。
  • Extension:WSOAuth – この MediaWiki 拡張機能は皆さんのウィキが Extension:OAuth を実行する場合も含めて、他のウィキに認証を委譲できるようにするもので 、対象は PluggableAuth を使用する全ての OAuth プロバイダになります。
  • Oauthclient-php – OAuth 消費者のクライアント・ライブラリ。