legacy-knowledge-base
公開されました Jun. 30, 2025

リモートサービスへのアクセスにクレデンシャルを使用する代わりにトークンシステムを導入する方法

written-by

Kanchan Bisht

How To articles are not official guidelines or officially supported documentation. They are community-contributed content and may not always reflect the latest updates to Liferay DXP. We welcome your feedback to improve How To articles!

While we make every effort to ensure this Knowledge Base is accurate, it may not always reflect the most recent updates or official guidelines.We appreciate your understanding and encourage you to reach out with any feedback or concerns.

legacy-article

learn-legacy-article-disclaimer-text

問題

  • Liferayを使ってカスタムリモートサービスを書こうとしています。

環境

  • Liferay DXP 7.4

解像度

  • Liferayには、Liferay PortalのAPIをリモートから呼び出す際に、一元的かつ拡張可能な方法で認証を行う認証ベリファイアがあります。 彼らには主に2つの責任がある:
    1. 登録された AuthVerifier インスタンスを使用して、提供された認証情報を検証する。
    2. 検証結果に基づいてポータル認証コンテキストを作成
    以下は、その詳細を知るためのドキュメントである: 認証ベリファイアの使用

    さらに、、Liferay には OAuth2 を作成するためのドキュメントがあります。 creating-oauth2-applications

    OAuth 2.0は認可プロトコルであり、認証プロトコルではありません。 そのため、主にリモートAPIやユーザーデータなど、一連のリソースへのアクセスを許可する手段として設計されている。

    OAuth 2.0は、同意されたアクセスを提供し、ユーザーの認証情報を共有することなく、ユーザーに代わってクライアントアプリがリソースに対して実行できるアクションを制限します。

1. DXPサーバーを起動。
2. コントロールパネルの「OAuth2管理」に移動。
3. OAuth2アプリケーションを追加しました。

Name: OAuth2
Website URL: http://localhost:8080/
Callback URIs: http://localhost:8080/
Client Authentication Method: Client Secret Post
Client Profile: Headless Server

4. 保存をクリックする。
5. Scopeに移動し、すべての「Portal Services」にチェックを入れる。
6. 以下のCURLコマンドを実行して、'Test'ユーザーのトークンを生成した:

curl -X POST --header "Content-Type: application/x-www-form-urlencoded" "localhost:8080/o/oauth2/token?grant_type=client_credentials&client_id={test-app-clientId}&client_secret={test-app-clientSecret}"

7. 次のようなレスポンスが返ってくるはずだ: {"accesstoken": "c625a7972685aeaf03d721cceeac11e8f917d73df5742f7a61b10278dd7c2c8", "tokentype": "Bearer", "expires_in":600, "scope": "liferay-json-web-services.everything.read.userprofile liferay-json-web-services.everything.write liferay-json-web-services.analytics.read liferay-json-web-services.analytics.write liferay-json-web-services.everything.read liferay-json-web-services.everything liferay-json-web-services.everything.read.documents.download"}.

トークンを受け取ったら、 Postman経由で任意のヘッドレスAPIでテストできる。

追加情報

did-this-article-resolve-your-issue

legacy-knowledge-base