「マイクロソフト系技術情報 Wiki」は、「Open棟梁Project」,「OSSコンソーシアム .NET開発基盤部会」によって運営されています。
JWT(JWS) Bearer Tokenをアサーションとして使用して、OAuth 2.0のAccess Tokenを要求する方法の定義。
ClientとResource Serverを統合するような状況下での利用が想定されている。
STSによってアサーションを取得する。
    Relying
    Party                     Client                   Token Service
      |                          |                         |
      |                          |  1) Request Assertion   |
      |                          |------------------------>|
      |                          |                         |
      |                          |  2) Assertion           |
      |                          |<------------------------|
      |    3) Assertion          |                         |
      |<-------------------------|                         |
      |                          |                         |
      |    4) OK or Failure      |                         |
      |------------------------->|                         |
      |                          |                         |
      |                          |                         |ローカルでアサーションを作成する。
    Relying
    Party                     Client
      |                          |
      |                          | 1) Create
      |                          |    Assertion
      |                          |--------------+
      |                          |              |
      |                          | 2) Assertion |
      |                          |<-------------+
      |    3) Assertion          |
      |<-------------------------|
      |                          |
      |    4) OK or Failure      |
      |------------------------->|
      |                          |
      |                          |できる。
RFC7523を参照。
要求された範囲は、OAuth 2.0 [RFC6749]の3.3節に記述されているとおり。
POST /token HTTP/1.1 Host: server.example.com Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3AX-bearer& assertion=SAML2 or JWT assertion
POST /token HTTP/1.1 Host: server.example.com Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code& code=n0esc3NRze7LTCu7iYzS6a5acc3f0ogp4& client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3AX-bearer& client_assertion=SAML2 or JWT assertion
HTTP/1.1 400 Bad Request Content-Type: application/json Cache-Control: no-store
{
 "error":"invalid_grant",
 "error_description":"Audience validation failed"
}HTTP/1.1 400 Bad Request Content-Type: application/json Cache-Control: no-store
{
 "error":"invalid_client"
 "error_description":"assertion has expired"
}以下を、アクセストークン・リクエストする。
{
  "alg": "RS256",
  "typ": "JWT"
}{
 "iss":"サービスアカウントのメールアドレス",
 "scope":"利用するAPIのスコープ",
 "aud":"https://www.googleapis.com/oauth2/v3/token",
 "exp":"トークンの有効期限To",
 "iat":"トークンの有効期限From",
}urn:ietf:params:oauth:grant-type:jwt-bearer
POST /token.oauth2 HTTP/1.1 Host: as.example.com Content-Type: application/x-www-form-urlencoded
grant_type=urn%3Aietf%3Aparams%3Aoauth%3Agrant-type%3Ajwt-bearer& assertion=...JWS...
クライアント認証は、オプション
以下のClaimが必要だが、IDトークンが参考になる。
JWT(JWS)の署名検証により、認証を行う。
{"alg": "ES256"、 "kid": "16"}{
 "iss":"https://jwt-idp.example.com",
 "sub":"mailto:mike@example.com",
 "aud":"https://jwt-rp.example.net",
 "nbf":1300815780,
 "exp":1300819380,
 "http://claims.example.com/member":true
}POST /token.oauth2 HTTP/1.1 Host: as.example.com Content-Type: application/x-www-form-urlencoded
grant_type=authorization_code& code=n0esc3NRze7LTCu7iYzS6a5acc3f0ogp4& client_assertion_type=urn%3Aietf%3Aparams%3Aoauth%3Aclient-assertion-type%3Ajwt-bearer& client_assertion=...JWS...
OAuth 2.0 を拡張するアサーションの仕様
- Client Authentication で Client Credentials として使うアサーションの仕様
 - Authorization Codeグラント種別のAccess Token と交換するアサーションの仕様
 - 単体では利用できず、後の2つのサブ仕様の共通部分を抽象化した仕様。
 
JWT を RFC 7521(上記) の アサーション として利用するための仕様
JWT を RFC 7521(上記) の アサーション として利用するための仕様
以下を見ると、
通常のOAuth 2.0の
以外に、
クライアント証明書(pfx形式の電子証明書)を使って、
サービスアカウントで認証する方法がある模様。
ちなみに、ここでは、Google.Apis.Analytics Client Libraryに
処理がラッピングされていたため。詳細が不明だったが、
以下を見ると、このClient Libraryの中では、JWTが使用されている模様。
これが、
「JWT bearer token authorizationグラント種別」
の用例である模様。
上記のサイトには、
Service Accounts = JWT Bearer Token Profile
であることが明記されている。
Googleと同様に、以下を見ると、
通常のOAuth 2.0の
以外に、
「JWT bearer token authorizationグラント種別」
をサポートしている模様。
ただし、処理は、ADAL(Active Directory Authentication Library)
にラップされているためJWT作成処理の詳細などを見ることは出来ない。
以下のQiita記事を参照すると、Salesforceは、
の2つのフローをサポートしている模様。
Tags: :認証基盤, :クレームベース認証, :OAuth