Oracle IAMのOIDC認証にてAPEXアプリとそれから呼び出すORDSのREST APIを認証する
https://apexugj.blogspot.com/2024/06/verification-of-oauth-create-jwt-profile-oracle-iam.html
Oracle IAMの統合アプリにカスタム・クレームを追加しRole based JWT profileによる保護を確認する
- 発行者(issuer)をデフォルトのhttps://identity.oraclecloud.com/としています。
- 署名証明書へのアクセスのクライアント・アクセスの構成を有効にしています。
- カスタム・クレームiam_groupsを作成しています。
追加するモバイル・アプリケーションの名前はORDS MCPとします。画面下部にある、認証と認可の権限付与を認可として実施をオンにします。このアプリケーションに割り当てられたユーザーおよびグループのみがサインインできるようになります。
送信をクリックします。
ORDS_SECURITY.CREATE_JWT_PROFILEを実行します。それぞれの引数には、今まで集めた設定値を割り当てます。引数p_role_claim_nameには、以前の記事で作成している/iam_groupsを指定します。
begin
ords_security.delete_jwt_profile;
ords_security.create_jwt_profile(
p_issuer => 'https://identity.oraclecloud.com/'
,p_audience => 'ドメインURL'
,p_jwk_url => 'ドメインURL/admin/v1/SigningCert/jwk'
,p_role_claim_name => '/iam_groups'
);
end;
/
以下のスクリプトを実行し、Oracle REST Data Servicesに権限oracle.example.mcpを作成(すでに存在する場合は再定義)します。ロールとしてORDSUsersを作成し、RESTモジュールsampleserverを保護します。
declare
l_roles owa.vc_arr;
l_modules owa.vc_arr;
l_patterns owa.vc_arr;
begin
ords.create_role(
p_role_name => 'ORDSUsers'
);
l_modules(1) := 'sampleserver';
l_roles(1) := 'ORDSUsers';
ords.define_privilege(
p_privilege_name => 'oracle.example.mcp',
p_label => 'Priviledge for MCP',
p_roles => l_roles,
p_modules => l_modules,
p_patterns => l_patterns -- no assignment
);
end;
/
[opc@apex ~]$ sudo -s
[root@apex opc]#
cd /usr/share/nginx/html
[root@apex opc]# cd /usr/share/nginx/html
[root@apex html]#
ディレクトリ.well-knownがすでに存在すれば名称を変えて保存し、新たに.well-knownを作成します。
mv .well-known well-known.bak
mkdir .well-known
[root@apex html]# mv .well-known well-known.bak
[root@apex html]# mkdir .well-known
[root@apex html]#
リモートMCPサーバーのアクセスパスが/ords/apexdev/sampleserver/mcpなので、oauth-protected-resourceとして記述する内容は.well-known以下の.well-known/oauth-protected-resource/ords/apexdev/sampleserver/mcpに記述します。
ファイル.well-known/oauth-protected-resource/ords/apexdev/sampleserver/mcpを作成し、以下を記述します。
{
"resource": "ドメインURL",
"authorization_servers": {
["ドメインURL/"]
}
}
authorization_serversの設定で、JSON配列を{}で囲んでJSONオブジェクトにしています。構文的に間違っているように思いますが、こうしないとMCP Inspectorがauthorization_serversを認識しません。メタデータをダウンロードし、.well-known以下に配置します。
curl -OL ドメインURL/.well-known/openid-configuration
mv openid-configuration .well-known/
[root@apex html]# curl -OL https://**********.identity.oraclecloud.com:443/.well-known/openid-configuration
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 3166 100 3166 0 0 36355 0 --:--:-- --:--:-- --:--:-- 36390
[root@apex html]# mv openid-configuration .well-known/
[root@apex html]#
MCP Inspectorを起動します。
npx @modelcontextprotocol/inspector
Transport TypeにStreamable HTTPを選択し、URLにORDSのRESTモジュールとして実装されているサンプルのMCPサーバーのURLを設定します。
https://ホスト名/ords/apexdev/sampleserver/mcp
OAuth 2.0 FlowのClient IDに、Oracle IAMに作成した統合アプリケーションORDS MCPのクライアントIDを設定します。
Connectをクリックし、認証プロセスを開始します。
以上でRole based JWT profileで保護したORDS REST APIを、MCP Inspectorでアクセスできました。
{
"resource": "ドメインURL",
"authorization_servers": {
["ドメインURL/"]
},
"scopes_supported": ["files:read", "files:write"]
}{
"resource": "ドメインURL",
"authorization_servers":
["ドメインURL/"]
,
"scopes_supported": ["files:read", "files:write"]
}





















































