マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。

目次

概要

特徴

モジュラーデザイン

ユースケースに対応するため、

多様な環境をサポートできる。

プロトコル概要

ざっくり、リクエスト→認証・認可→ユーザ情報を取得。

+--------+                                   +--------+
|        |                                   |        |
|        |---------(1) AuthN Request-------->|        |
|        |                                   |        |
|        |  +--------+                       |        |
|        |  |        |                       |        |
|        |  |  End-  |<--(2) AuthN & AuthZ-->|        |
|        |  |  User  |                       |        |
|   RP   |  |        |                       |   OP   |
|        |  +--------+                       |        |
|        |                                   |        |
|        |<--------(3) AuthN Response--------|        |
|        |                                   |        |
|        |---------(4) UserInfo Request----->|        |
|        |                                   |        |
|        |<--------(5) UserInfo Response-----|        |
|        |                                   |        |
+--------+                                   +--------+

OAuth 2.0に認証拡張

OAuth 2.0との違いは、認証拡張機能が実装された点にある。

仕様一覧

OAuth 2.0に認証結果とプロフィールの受渡し機能を追加

OAuth 2.0に認証結果とプロフィールの受渡し機能のみを追加した仕様

OpenID Connectのコアな機能(難しいことも可能に)

リクエスト内の細かいクレーム指定や認証コンテキストの指定

関連仕様

認証のシーケンス

Authorization Code Flow

OAuth 2.0 からのステップ上の拡張部分は無い。
ただし、アクセス先がResources ServerのEndpointがUserInfo?エンドポイントに特定されており、
ここから、認証されたユーザ情報としてユーザー属性クレーム群を取得している。

  1. Client prepares an Authentication Request containing the desired request parameters.
  2. Client sends the request to the Authorization Server.
  3. Authorization Server Authenticates the End-User.
  4. Authorization Server obtains End-User Consent/Authorization.
  5. Authorization Server sends the End-User back to the Client with an Authorization Code.
  6. Client requests a response using the Authorization Code at the Token Endpoint.
  7. Client receives a response that contains an ID Token and Access Token in the response body.
  8. Client validates the ID token and retrieves the End-User's Subject Identifier.

Implicit Flow

朱書きは、OAuth 2.0 からのステップ上の変更・拡張部分。
ポイントは、User-Agentやスマホネイティブから直接的にAccess Tokenを使用せず、
ClientにAccess Tokenを送って、そこからユーザー属性クレーム群を取得している点。

  1. Client prepares an Authentication Request containing the desired request parameters.
  2. Client sends the request to the Authorization Server.
  3. Authorization Server Authenticates the End-User.
  4. Authorization Server obtains End-User Consent/Authorization.
  5. Authorization Server sends the End-User back to the Client with an ID Token and, if requested, an Access Token.
  6. Client validates the ID token and retrieves the End-User's Subject Identifier.

Hybrid Flow

朱書きは、Authorization Code Flowとの差異。

ID トークンと同時に、アクセストークンや認可コードが一緒に発行される場合、
ID トークンにat_hash、c_hashクレームが追加される(用途不明)。

  1. Client prepares an Authentication Request containing the desired request parameters.
  2. Client sends the request to the Authorization Server.
  3. Authorization Server Authenticates the End-User.
  4. Authorization Server obtains End-User Consent/Authorization.
  5. Authorization Server sends the End-User back to the Client with an Authorization Code and,
    depending on the Response Type, one or more additional parameters.
  6. Client requests a response using the Authorization Code at the Token Endpoint.
  7. Client receives a response that contains an ID Token and Access Token in the response body.
  8. Client validates the ID Token and retrieves the End-User's Subject Identifier.

IDトークン(クレーム)

概要

ID トークンは JWT の一種

メッセージ形式にJSONを採用

JWT : JSON Web Tokenの略

クレーム暗号化

JWTのJWS or JWEを使用する。

クレームセット

必須クレーム群

ケースバイケースなクレーム群

オプションのクレーム群

外部クレーム

Idp(OP)は、扱うクレームの内容によって、

どちらを利用すべきかを判断する必要がある。

集約クレーム

一定期間変更されないことが保証されており
キャッシュの効果があるものは集約クレーム。

分散クレーム

クレームそのものではなく、問い合わせ先のURLを扱う。

をレスポンスに含む。

頻繁に更新されるものは分散クレーム。

Google

GoogleでOpenID Connectの認証で取得したクレームセット。
(id_tokenそのものなのか?、UserInfo?エンドポイントから取得したクレームか?)

{
  "iss":"accounts.google.com",
  "at_hash":"・・・", ← Hybrid Flowの追加クレーム
  "email_verified":"true",
  "sub":"ユーザーの一意識別子",
  "azp":"認可された対象者のID.apps.googleusercontent.com",
  "email":"・・・・",
  "aud":"クライアント識別子.apps.googleusercontent.com",
  "iat":JWT の発行日時(Unix時間),
  "exp":JWT の有効期限(Unix時間)
}

ココを見ると、これは恐らく、id_tokenなのだろうなと。

以下のGoogle公式のマニュアルにも記載があった。

ユーザー属性クレーム群

Standard Claims

項番クレーム名意味
1subユーザーの一意識別子
2nameフルネーム
3given_name
4family_name
5middle_nameミドルネーム
6nicknameニックネーム
7preferred_username好みのユーザー名
8profileプロフィールページの URL
9pictureプロフィール画像の URL
10websiteWeb サイトやブログの URL
11emailメールアドレス
12email_verifiedメールアドレスが検証済みか否かの真偽値
13gender性別。female と male が定義済み。
14birthdate誕生日。YYYY-MM-DD。
15zoneinfoタイムゾーン。Europe/Paris など。
16localeロケール。en-US など。
17phone_number電話番号
18phone_number_verified電話番号が検証済みか否かの真偽値
19address住所。書式は「5.1.1. Address Claim」に記載。
20updated_at情報最終更新日。Unix エポックからの経過秒数。

Address Claim

項番クレーム名意味
1formattedフォーマットされたフルメールアドレス、表示用・郵送用に使用
2street_address通り・番地、号室、私書箱、複数行の拡張された住所情報。
3localityCity or locality
4regionState, province, prefecture, or region.
5postal_codeZip code or postal code
6countryCountry name

多言語化

OpenID Connectのシーケンス

STEP 0 は事前準備なので、STEP 1 からが実際の認証・認可のシーケンス。

Webアプリ(Basic Client Profile)

STEP 0 : 事前準備(Idp(OP)にRPを登録)

Idp(OP)にRPを登録し、

を入手する。

STEP 1 : Authorization codeの取得

RPがIdp(OP)からAuthorization codeを取得。

STEP 2 : Access Token、ID Tokenの取得

STEP 3 : IDトークンの正当性の検証

"access_token"の

STEP 4 : 属性情報の取得

モバイルアプリ(Implicit Client Profile)

STEP 0 : Discovery & Dynamic Client Registration

IdP(OP)探索と動的なRP登録

結果的に、OPからRP識別のための“cient_id”がレスポンスされる。

STEP 1 : Authorization Request

認可リクエスト

STEP 2 : Authorization Response

認可応答

STEP 3 : ID Token Verification

IDトークンの検証

STEP 4 : Accessing to UserInfo? Endpoint

UserInfo?エンドポイントへのアクセス

参考

OpenID Foundation

IdM実験室

WIF

WIF Extension for OAuthは古い?

OWIN

Microsoft.Owin.Security.OpenIdConnect?

ADFS

Tsmatz

上記のコンテンツの内容を確認すると、

双方に対応した v2.0 endpoint (App Model v2) と連携し、
OAuth 2.0(ではなく、OpenID Connect)認証をおこない、
認証結果を他の API (Service) で検証し認証させている。

サンプルを実行する方法

Microsoft.Owin.Security.OpenIdConnect?

https://github.com/OpenTouryoProject/SampleProgram/tree/master/ASPNET/OpenID_Connect/

サンプル・アプリケーションをAzure Active Directoryに登録

  1. Azureの管理ポータルにサインイン。
  2. Azure Active Directoryのタブを開く。
  3. サンプル・アプリケーションを登録するテナント(ドメイン)を開く。
  4. [Applications]タブに移動し、ページの下部の[Add]アイコンををクリック。
  5. [What do you want to do?]画面で[Add an application my organization is developing]を選択。
  6. [Tell us about your application]画面が表示される。
    1. アプリケーションの名前を入力(例:OpenIDConnect_sample)。
    2. [Web Application and / or Web API]を選択する。
    3. [Next]をクリックする。
  7. [App properties]画面が表示される。
    1. サンプルのサインオンURLを入力(例:https://localhost:xxxxxx/
      サンプル・プロジェクトのプロパティにある開発サーバのSSL URLプロパティを指定
      http://www.codeproject.com/Tips/766918/Visual-Studio-Use-HTTPS-SSL-On-Web-Application-Pro
    2. アプリのID URIを入力(例:https://<your_tenant_name>/OpenIDConnect_sample)
      '<your_tenant_name>はAzure ADのテナント(ドメイン)名。
    3. [Complete]をクリック。

サンプル・アプリケーションの構成

  1. web.configファイルを開く。
  2. FxTenant?にAzure ADのテナント(ドメイン)名を指定(例:xxxxx.onmicrosoft.com)
  3. FxClientId? にAzureのポータルから入手することができるClient IDを指定
    1. クライアントIDを取得するには、
    2. Azureの管理ポータルにサインイン。
    3. Azure Active Directoryのタブを開く。
    4. サンプル・アプリケーションを登録したテナント(ドメイン)を開く。
    5. [Applications]タブに移動しサンプル・アプリケーションを選択。
    6. アプリケーション画面で[ACCESS WEB APIS IN OTHER APPLICATIONS]を選択。
    7. Client IDをコピー。
  4. FxPostLogoutRedirectUri?にサンプルのサインオンURLを入力(例:https://localhost:xxxxxx/

サンプル・アプリケーションの構成

F5実行でリダイレクトされた先のAzure AD(STS)で認証できることを確認する。


Tags: :認証基盤, :クレームベース認証


トップ   新規 一覧 単語検索 最終更新   ヘルプ   最終更新のRSS