Extension:OAuth
リリースの状態: 安定 |
|
|---|---|
| 実装 | 利用者識別, 利用者権限, API |
| 説明 | 利用者が自分の代わりに MediaWiki API を使用する別のアプリケーション ("consumer") を安全に認可できるようにする。 |
| 作者 | Aaron Schulz, Chris Steipp, Brad Jorsch, Robert Vogel, Dejan Savuljesku |
| 最新バージョン | 1.1.0 (continuous updates) |
| 互換性の方針 | スナップショットが MediaWiki とともにリリースされます。 master には後方互換性がありません。 |
| データベースの変更 | はい |
| 仮想ドメイン | virtual-oauth |
|
|
|
|
|
|
|
| ライセンス | GNU 一般公衆利用許諾書 2.0 以降 |
| ダウンロード | |
| ヘルプ | Help:OAuth |
| translatewiki.net で翻訳を利用できる場合は、OAuth 拡張機能の翻訳にご協力ください | |
| Vagrant role | oauth |
| 問題点 | 未解決のタスク · バグを報告 |
OAuth 拡張機能が実装するMediaWikiのOAuthサーバは、プロトコル版番号 OAuth 1.0a と OAuth 2.0 の両方に対応しています。 これによりサードパーティの開発者はアプリケーション (「消費者」) を安全に開発でき、利用者は付与する権限一式 (「承諾」) を限定できるため、利用者に代わってそのアプリケーションに MediaWiki API を使用させます。
要件
- OAuthは一時的なトークンとセッションのためにオブジェクトキャッシュに依存しています。 キャッシュ構成設定がまともな限り、うまくいくはずです。 (Older versions required Memcached explicitly.)
- 現在、MySQLとSQLiteのデータベースバックエンドのみをサポートしています。
- MediaWiki のインストールがプライベートの場合(利用者は必ずログインして閲覧許可を得る場合)、Special:OAuthをホワイトリストに加筆して対応できるかもしれません。
インストール
- ダウンロードして、ファイルを
extensions/フォルダー内のOAuthという名前のディレクトリ内に配置します。
開発者とコード寄稿者は、上記の代わりに以下を使用してGitからインストールします:cd extensions/ git clone https://gerrit.wikimedia.org/r/mediawiki/extensions/OAuth
- Gitでのインストールの場合のみ、PHPの依存関係をインストールするためComposerを実行します。 (合併症の可能性についてはT173141を参照。)
- 以下のコードを LocalSettings.php ファイルの末尾に追加します:
wfLoadExtension( 'OAuth' );
- 更新スクリプトを実行します。このスクリプトは、この拡張機能が必要とするデータベーステーブルを自動的に作成します。
- 必要に応じて一般的なパラメーターを設定します。
- OAuth2 will not be enabled if you leave all settings at their defaults.
- 利用者権限の設定は、
$wgGroupPermissionsの該当するグループ配下に置くと実行されます。
完了 – ウィキの「Special:Version」に移動して、拡張機能が正しくインストールされたことを確認します。
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;
Database virtual domains mapping
Since MediaWiki 1.45, it's recommended to configure database virtual domains mapping for OAuth, see this patch.
$wgMWOAuthCentralWiki and virtual domains are separate settings.
To set up virtual domains mapping with OAuth, use:
$wgMWOAuthCentralWiki = '<central-wiki>';
$wgVirtualDomainsMapping['virtual-oauth'] = [ 'db' => '<oauth-db>' ];
設定
パラメーター
| 変数名 | 既定値 | 説明 |
|---|---|---|
$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 |
$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. $wgSessionCacheType の場合、既定値は $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付与を管理 |
エンドポイント
The following REST endpoints are provided for OAuth 2.0 interaction
Get authorization code
Used for retrieving authorization code when using authorization_code grant.
- パス
- /oauth2/authorize
- 許容されるメソッド
- GET
- 許容されるパラメーター
名前 必須かどうか 説明 response_type はい client_id はい redirect_uri いいえ これがあるとクライアントの登録時に送信した URI とまったく同一でなければなりません scope いいえ state いいえ code_challenge いいえ $wgOAuth2RequireCodeChallengeForPublicClientsがの場合に必須truecode_challenge_method いいえ $wgOAuth2RequireCodeChallengeForPublicClientsがの場合に必須true
Get access token
Used for requesting access tokens
- パス
- /oauth2/access_token
- 許容されるメソッド
- POST
- 許容されるパラメーター
名前 必須かどうか 説明 grant_type はい type of grant used client_id いいえ client_secret いいえ クライアントが confidentialの場合に必須redirect_uri いいえ これがあるとクライアントの登録時に送信した URI とまったく同一でなければなりません scope いいえ code いいえ authorization_code承諾の採用に必須refresh_token いいえ refresh_token承諾の採用に必須code_verifier いいえ
Get user or client information
前に発行したアクセストークンを採用して、保護されたリソースの取得に使います。
現状でこのエンドポイントから取得できるリソースは2樹類あり、{{type}} プレースフォルダを以下のタイプキーに切り替えます。
profile- 利用者のプロファイルを取得するとき、リクエストに採用するアクセストークン - 通常は MediaWiki を使う利用者がサードパーティの Web サイトへのログイン時に適用するものを使い、それに対応する利用者を対象とします。scopes- すべてのスコープのクライアント(アプリケーション)取得は現在のアクセストークンと併用できる
- パス
- /oauth2/resource/{{type}}
- 許容されるメソッド
- GET
- POST
- 許容されるパラメーター
- パラメータは使えず、唯一の例外はパスに含まれる
{{type}}パラメータ
List clients
ログイン利用者について OAuth 1.0a または 2.0 クライアントを一覧にします。 認証は CentralAuth 経由、または認証ヘッダにアクセス・トークンを書き込んでも実施します。
- パス
- /oauth2/client
- 許容されるメソッド
- GET
- 許容されるパラメーター
oauth_version(省略可能) – 設定値は1(戻し値は OAuth 1.0a クライアント限定)または 2(戻し値は OAuth 2.0 クライアント限定)。 既定値: 2- Pagination parameters
limit(省略可能) – 返すクライアント件数の上限値。 既定値: 25offset(省略可能) – 最初の結果を返す前にスキップするクライアントの件数。 既定値: 0
| レスポンスの例 |
|---|
{
"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
}
|
Reset client secret
クライアントのシークレットをリセット。 所有者専用クライアントの場合、このエンドポイントはアクセス トークンもリセットします。
- パス
- /oauth2/client/{client_key}/reset_secret
- 許容されるメソッド
- POST
- 許容されるパラメーター
名前 必須かどうか 説明 既定 client_keyはい クライアントの識別子 reasonいいえ シークレットをリセットする理由を述べた文字列。 ''
| レスポンスの例 |
|---|
{
"name": "Example",
"client_key": "xxxxxxxxxx",
"secret": "xxxxxxxxxx",
"access_token": "xxxxxxxxxx"
}
|
Create OAuth 2.0 client
OAuth 2.0 クライアントを作成。
- パス
- /oauth2/client
- 許容されるメソッド
- POST
- 許容されるパラメーター
名前 必須かどうか 説明 既定 nameはい クライアントの名称 descriptionはい クライアントの説明 emailはい 問い合わせ先のメールアドレス is_confidentialはい クライアントが機密保持型の場合は true に設定、モバイルやデスクトップアプリなど公開クライアントは false に設定 grant_typesはい クライアントが適用する OAuth 2.0 承諾の種別 は以下のうちの1件または複数です。 authorization_code,refresh_token,client_credentialsscopesはい OAuth 2.0 の適用範囲は mwoauth-authonly、mwoauth-authonlyprivateもしくは適用する承諾の一式のいずれかversionいいえ クライアントのバージョン。 1.0 wikiいいえ 対応するプロジェクト。 * は全てのウィキに対応 owner_only? true に設定、作成者である利用者しか使わないクライアントに限定 callback_urlいいえ 権限のある利用者に URL を返します。 ''callback_is_prefixいいえ true に設定、クライアントが リクエストのコールバック確認と必須の前置詞としてコールバック URL を使えるようにします。 false
| レスポンスの例 |
|---|
{
"name": "Example",
"client_key": "xxxxxxxxxx",
"secret": "xxxxxxxxxx",
"access_token": "xxxxxxxxxx"
}
|
関連項目
- Extension:OATHAuth – 名称が似た拡張機能で、OATH-基準のワンタイムパスワードを使う二次的な認証ファクタを採用します。
- Extension:WSOAuth – この MediaWiki 拡張機能は皆さんのウィキが Extension:OAuth を実行する場合も含めて、他のウィキに認証を委譲できるようにするもので 、対象は PluggableAuth を使用する全ての OAuth プロバイダになります。
- Oauthclient-php – OAuth 消費者のクライアント・ライブラリ。
| この拡張機能は 1 つ以上のウィキメディアのプロジェクトで使用されています。 これはおそらく、この拡張機能が安定していて高いトラフィックのウェブサイトでも十分に動作することを意味します。 この拡張機能がインストールされている場所を確認するには、ウィキメディアの設定ファイル CommonSettings.php および InitialiseSettings.php 内で、この拡張機能の名前を探してください。 特定のウィキにインストールされている拡張機能の完全な一覧は、そのウィキの Special:Version ページにあります。 |
| この拡張機能は以下のウィキ ファーム/ウィキ ホスト/パッケージに含まれています: |
- Stable extensions/ja
- User identity extensions/ja
- User rights extensions/ja
- API extensions/ja
- Extensions which add rights/ja
- AbuseFilter-builder extensions/ja
- AbuseFilter-computeVariable extensions/ja
- AbuseFilter-generateUserVars extensions/ja
- ApiRsdServiceApis extensions/ja
- BeforeCreateEchoEvent extensions/ja
- ChangeTagCanCreate extensions/ja
- ChangeTagsListActive extensions/ja
- GetPreferences extensions/ja
- ListDefinedTags extensions/ja
- LoadExtensionSchemaUpdates extensions/ja
- LoginFormValidErrorMessages extensions/ja
- MediaWikiServices extensions/ja
- MergeAccountFromTo extensions/ja
- MessagesPreLoad extensions/ja
- SetupAfterCache extensions/ja
- SpecialPageAfterExecute extensions/ja
- SpecialPageBeforeFormDisplay extensions/ja
- TestCanonicalRedirect extensions/ja
- GPL licensed extensions/ja
- Extensions in Wikimedia version control/ja
- All extensions/ja
- Extensions requiring Composer with git/ja
- Extensions used on Wikimedia/ja
- Extensions included in Canasta/ja
- Extensions included in Miraheze/ja
- Extensions included in ProWiki/ja
- Extensions included in Telepedia/ja
- Extensions included in Weird Gloop/ja
- Extensions included in wiki.gg/ja
