マイクロソフト系技術情報 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に認証結果とプロフィールの受渡し機能を追加。

ID トークン

追加のエンドポイント

フロー

Authorization Code Flow

概要

OAuth 2.0 からのステップ上の拡張部分は無い。

ただし、

ステップ

The Authorization Code Flow goes through the following steps.

  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 からのステップ上の変更・拡張部分。

ステップ

The Implicit Flow follows the following steps:

  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

概要

フローとしては、Implicit Flowに近く、
ID トークンと同時に、アクセストークンや認可コードが一緒に発行される。

ID トークンat_hash、c_hashクレームが追加される。

ステップ

The Hybrid Flow follows the following steps:

  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.

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

IDトークン

概要

クレームセット

必須クレーム群

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

オプションのクレーム群

Hybrid Flowのクレーム

Hybrid Flowの場合、以下が必須。

ユーザー属性クレーム群

その他、ユーザー属性クレーム群を格納する。

外部クレーム

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

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

集約クレーム(Aggregated Claims)

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

分散クレーム(Distributed Claims)

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

をレスポンスに含む。

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

Google

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

{
  "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ユーザーの一意識別子
2profileプロフィール
2-1nameフルネーム
2-2given_name
2-3family_name
2-4middle_nameミドルネーム
2-5nicknameニックネーム
2-6preferred_username好みのユーザー名
2-7profileプロフィールページの URL
2-8pictureプロフィール画像の URL
2-9websiteWeb サイトやブログの URL
2-10gender性別。female と male が定義済み。
2-11birthdate誕生日。YYYY-MM-DD。
2-12zoneinfoタイムゾーン。Europe/Paris など。
2-13localeロケール。en-US など。
2-14updated_at情報最終更新日。Unix エポックからの経過秒数。
3email電子メール
3-1email電子メールアドレス
3-2email_verified電子メールアドレスが検証済みか否かの真偽値
4phone電話
4-1phone_number電話番号
4-2phone_number_verified電話番号が検証済みか否かの真偽値
5address住所 JSON object。書式は「5.1.1. Address Claim」に記載。
5-1formattedフォーマットされたフルメールアドレス、表示用・郵送用に使用
5-2street_address通り・番地、号室、私書箱、複数行の拡張された住所情報。
5-3localityCity or locality
5-4regionState, province, prefecture, or region.
5-5postal_codeZip code or postal code
5-6countryCountry name

多言語化

ユーザー属性クレーム群の格納要求

scope値による格納要求

scope値によってユーザー属性クレーム群の格納要求を行うことができる。

グループ名

前述のグループ名(profile, email, phone, address)をscope値に指定可能。

格納部位

クレーム要求JSONによる格納要求

トップレベルメンバ

クレーム要求JSONの例

クレーム要求JSONの例を以下に示す:

 {
  "userinfo":
   {
    "given_name": {"essential": true},
    "nickname": null,
    "email": {"essential": true},
    "email_verified": {"essential": true},
    "picture": null,
    "http://example.info/claims/groups": null
   },
  "id_token":
   {
    "auth_time": {"essential": true},
    "acr": {"values": ["urn:mace:incommon:iap:silver"] }
   }
 }

ユーザー情報エンドポイント

概要

リクエスト

レスポンス

Discovery、Dynamic Client Registrationとの関連

この仕様は、Discovery、Dynamic Client Registrationと関係がある。

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

ユーザー情報エンドポイントへのアクセス

その他

比較的、重要度の高い仕様についてまとめる。

claimsリクエスト・パラメタ

認証コンテキストクラス

識別子

Authentication Context Class Reference(ACR)識別子。

要求方法

arcクレームをscopeやclaimsリクエスト・パラメタで要求できる。

参考

https://qiita.com/TakahikoKawasaki/items/185d34814eb9f7ac7ef3#16-%E8%AA%8D%E8%A8%BC%E3%82%B3%E3%83%B3%E3%83%86%E3%82%AD%E3%82%B9%E3%83%88%E3%82%AF%E3%83%A9%E3%82%B9

リクエスト・オブジェクト

認可エンドポイントに渡すリクエスト・パラメタ群を
JWT形式(認証要求に署名し、オプションで暗号化できる)で渡す方法。

渡し方

処理

参考

参考

OpenID Foundation

Client Implementer's Guide

WebアプリケーションのClientに当該フローを実装する場合の実装ガイド。

関連仕様

IdM実験室

WIF

WIF Extension for OAuthは古い?

OWIN

Microsoft.Owin.Security.OpenIdConnect?

ADFS

Microsoft Azure Active Directory

OpenId? Connectのサンプル

Microsoft.Owin.Security.OpenIdConnect?

AzureADに対して、OpenId? Connectを使用して認証する。

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