Node.js Application and SDKを調べてください
ソリューションのこのセクションでは、次の操作を行います。
-
Node.js Webアプリケーションの動作とコードを調べる
-
Node.js WebアプリケーションがOracle Identity Cloud Serviceに開始する、成功したログイン試行と失敗したログイン試行に関連する診断データを確認します
Node.js Applicationの動作を確認してください
Node.js Webアプリケーションの動作は、認可コード権限タイプで定義された3レッグ認証フローに従います。
アプリケーションとOracle Identity Cloud ServiceがWebブラウザを使用して実行しているすべてのリクエスト、レスポンスおよびリダイレクトを検証するには、ブラウザのDeveloperモードを有効にします。このソリューションではGoogle Chromeを使用します。
ブラウザの開発者ログには、次のイベント・フローが表示されます。
-
/auth/oracle
リソースをリクエストすると、WebブラウザにNode.js Webアプリケーションからのリダイレクト・レスポンスが送信されます。Request URL: http://localhost:3000/auth/oracle Request Method: GET Status Code: 302 Found Response Headers Location: https://idcs-1234.identity.oraclecloud.com/oauth2/v1/authorize?client_id=123456789abcdefghij&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&response_type=code&scope=openid&state=1234
-
Oracle Identity Cloud Serviceは、承認コード要求を受け取り、サインイン・ページを表示します。
Request URL: https://idcs-1234.identity.oraclecloud.com/oauth2/v1/authorize?client_id=123456789abcdefghij&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Fcallback&response_type=code&scope=openid&state=1234Request Method: GET Status Code: 303 See Other Response Headers Location: https://idcs-abcd1234.identity.oraclecloud.com/ui/v1/signin Set-cookie: ORA_OCIS_REQ_1=[value has been omitted for readability]
-
Oracle Identity Cloud Serviceにサインインします。Oracle Identity Cloud Serviceは、WebブラウザをNode.js WebアプリケーションのコールバックURLにリダイレクトします。
Request URL: http://localhost:3000/callback?code=[value has been omitted for readability]&state=1234 Request Method: GET Status Code: 302 Found Response Hearders Location: /auth.html Set-Cookie: idcs_user_assertion=[value has been omitted for readability]
この例では、コールバックURLによって、ユーザー・アクセス・トークンがCookieとして設定されたWebブラウザが/auth.html
ページにリダイレクトされます。
この時点で、アプリケーションはpassport.authenticate()
メソッドを使用してローカルで認証を行い、リクエストを/home
ルートに転送します。
Request URL: http://localhost:3000/home
Request Method: GET
Status Code: 200 OK
Response Headers
Cookie:
connect.sid=[value has been omitted for readability]
Node.jsアプリケーションのコードを調べてください
Oracle Identity Cloud Serviceにサインインし、Node.js WebアプリケーションのコールバックURLにリダイレクトされると、Node.js Webアプリケーションはコマンド行ウィンドウに情報をログに記録します。
req.user={"name":"your.email@domain.com","displayName":"Your Name","id":"111111111111","tenant":"idcs-abcd1234","groups":[{"name":"Group 1","id":"2222222222222","location":"https://idcs-abcd1234.identity.oraclecloud.com/admin/v1/Groups/7787fbab31b34e08b39cdeedf1f4233a"}],"appRoles":[{"name":"Identity Domain Administrator","id":"333333333333333","location":"https://idcs-abcd1234.identity.oraclecloud.com/admin/v1/AppRoles/444444444444444","appName":"SampleApp","appID":"SampleAppId"}],"client":{"client_name":"Sample Apps","client_id":"555555555555","client_tenantname":"idcs-abcd1234","scope":"openid","audience":"https://idcs-abcd1234.identity.oraclecloud.com"}}
ensureAuthenticated()
メソッドは、Oracle Identity Cloud Serviceにサインインした、ユーザーを表すJSONオブジェクトに関する情報を記録します。
ensureAuthenticated req.user={"name":"your.email@domain.com","displayName":"Your Name","id":"111111111111","tenant":"idcs-abcd1234","groups":[{"name":"Group 1","id":"2222222222222","location":"https://idcs-abcd1234.identity.oraclecloud.com/admin/v1/Groups/7787fbab31b34e08b39cdeedf1f4233a"}],"appRoles":[{"name":"Identity Domain Administrator","id":"333333333333333","location":"https://idcs-abcd1234.identity.oraclecloud.com/admin/v1/AppRoles/444444444444444","appName":"SampleApp","appID":"SampleAppId"}],"client":{"client_name":"Sample Apps","client_id":"555555555555","client_tenantname":"idcs-abcd1234","scope":"openid","audience":"https://idcs-abcd1234.identity.oraclecloud.com"}}
診断データの確認
Node.js WebアプリケーションがOracle Identity Cloud Serviceに開始する成功したログイン試行と失敗したログイン試行は、Oracle Identity Cloud Serviceの診断ログ・ファイルに登録されています。
- Oracle Identity Cloud Serviceにサインインします。
- Identity Cloud Serviceコンソールで、ナビゲーション・ドロワーを展開し、「設定」、「診断」の順にクリックします。
- 診断タイプとして「アクティビティ表示」を選択し、「保存」をクリックします。
- Oracle Identity Cloud Serviceからサインアウトします。
Oracle Identity Cloud Serviceは、次の15分の診断データを取得します。
-
Node.js Webアプリケーションの「ログイン」ページを表示するには、このソリューションの「Node.js Applicationの実行」トピックのステップを完了します。
-
右側に表示される赤色のOracleアイコンまたは「次でログインできます。」アイコンをクリックします。
-
サインインに失敗した場合は、Oracle Identity Cloud Service「サインイン」ページで正しくないユーザー名またはパスワードを入力します。
-
正常にサインインするには、正しいユーザー名とパスワードを入力します。
-
Node.js Webアプリケーションを使用して、Oracle Identity Cloud Serviceからサインアウトします。
-
Oracle Identity Cloud Serviceに再度サインインします。
-
Identity Cloud Serviceコンソールで、「ナビゲーション・ドロワー」を展開し、「レポート」、「診断データ」の順にクリックします。
-
時間範囲の「15-Minute」、ログ・タイプのアクティビティ・ビュー、レポート形式のCSVを選択し、「レポートのダウンロード」をクリックします。
診断ログ・ファイルには、Oracle Identity Cloud Serviceにサインインしているユーザーに関する次のような情報が含まれています。
Message: ID Token will be signed with User Tenant:idcs-abcd1234 Resource Tenant:idcs-abcd1234, clientId=123456789abcdefghij
Component: OAuth
Timestamp: [Date]
Actor ID: your.email@example.com
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: {"request":{"tenant":"idcs-abcd1234","grant types":"authorization_code","scopes":["urn:opc:idm:t.user.me"]},"user":{"id":"111111","name":"your.email@example.com","tenant":"idcs-abcd1234","auth-type":"PASSWORD"},"client":{"id":"123456789abcdefghij","name":"Sample App","tenant":"idcs-abcd1234","auth-type":"PASSWORD"},"environment":{"isCSR":"false","onBehalfOfUser":"false"},"response":{"result":"ALLOWED","scopes":["urn:opc:idm:t.user.me"],"custom-claims":{"clientAppRoles":["Authenticated Client","Me"],"userAppRoles":["Authenticated","Global Viewer","Identity Domain Administrator"],"user_isAdmin":"true"}}}
Component: Authorization/getAllowedScopes
Timestamp: [Date]
Actor ID: your.email@example.com
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: {"Message":"SSO SignOn Policy evaluation result for user : 11111 is : effect:ALLOW,authenticationFactor:IDP,allowUserToSkip2FAEnrolment:false,2FAFrequency:SESSION,reAuthenticate:false,trustedDevice2FAFrequency:
Component:
Timestamp:
Actor ID:
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: [PolicyEngineUtil.evaluatePolicy] Evaluating Default Sign-On Policy
Component: PolicyEngine
Timestamp: [Date]
Actor ID: uiSignin
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: [PolicyEngineUtil.evaluateRule] Evaluating MFA rule
Component: PolicyEngine
Timestamp: [Date]
Actor ID: uiSignin
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: [PolicyEngineUtil.evaluatePolicy] Evaluating Default Authentication Target App Policy
Component: PolicyEngine
Timestamp: [Date]
Actor ID: idcssso
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: {"password":"********","authFactor":"USERNAME_PASSWORD","device":"{\"currentTime\":\"[date]",\"screenWidth\":1920,\"screenHeight\":1080,\"screenColorDepth\":24,\"screenPixelDepth\":24,\"windowPixelRatio\":1,\"language\":\"en\",\"userAgent\":\"Mozilla\/5.0 (Windows NT 10.0
Component:
Timestamp:
Actor ID:
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: {"Message":"No session found so need to collect credentials","Redirecting to Login URL: ":https://idcs-abcd1234.identity.oraclecloud.com/ui/v1/signin}
Component: SSO
Timestamp: [Date]
Actor ID: Unauthenticated
---------------------------------------------------------------
...
---------------------------------------------------------------
Message: [PolicyEngineUtil.evaluatePolicy] Evaluating Default Identity Provider Policy
Component: PolicyEngine
Timestamp: [Date]
Actor ID: Unauthenticated
---------------------------------------------------------------
Message: Authorization Request, received parameters: scope[urn:opc:idm:t.user.me openid] response_type[code] state[1234] redirect_uri[http://localhost:3000/callback] client_id[123456789abcdefghij]
Component: OAuth
Timestamp: [Date]
Actor ID: Unauthenticated
最新のログがファイルの先頭に表示されます。