[[Open棟梁Project>http://opentouryo.osscons.jp/]] - [[マイクロソフト系技術情報 Wiki>http://techinfoofmicrosofttech.osscons.jp/]] -[[戻る>クレームベース認証#k66961ce]] * 目次 [#qc1590f2] #contents *概要 [#ff7046a2] -[[戻る>クレームベース認証#k66961ce]] *変遷 [#k3aeda5b] **OAuth 1.0 [#eb4fd2ef] -OpenIDを使ってTwitterやMa.gnoliaのAPIの認証委譲する方法を議論を開始。 -2007/4にOAuthのコミュニティが誕生。 -2007/7にOAuthの仕様の草案が完成。 -2007/10/3に、より正式な仕様であるOAuth Core 1.0 の最終草案がリリース。 -2008/11、第73回のIETF会合でOAuthの非公式会合も開かれ、~ さらなる標準化に向けてIETFにOAuthプロトコルを提案するかどうかを議論。 -2009/4/23、OAuth 1.0のセキュリティ問題が判明。この問題は、OAuth 1.0aで修正された。 **OAuth 2.0 [#h8e684ba] -OAuth 1.0とは後方互換性を持たない。 -次世代のOAuthプロトコルとして、2012年にRFCとして発行された。 **OAuth 1.0とOAuth 2.0の違い [#s44d10cb] -OAuth 2.0でWebサービスの利用方法はどう変わるか(2-3)- @IT~ http://www.atmarkit.co.jp/fsmart/articles/oauth2/02.html +HTTPSを必須にし、署名をなくし、トークン取得も簡略化 +アクセストークンのみでリソース取得が可能に +Webアプリも含め、4つのクライアントプロファイルを仕様化 ++Webサーバ(Web Server)~ Webアプリケーション ++ユーザーエージェント(User-Agent) ~ JavaScript ++ネイティブアプリ(Native Application)~ モバイルやデスクトップアプリ(ガイドライン程度しか定義されていない) ++自立クライアント(Autonomous)~ 既存の認証フレームワークとSAMLなどのプロトコルを使って連携する場合のフロー。 **Bearer Token Usage [#c954189a] -OAuth 2.0のbearer tokenの最新仕様を調べたらあまり変わってなかった - r-weblife~ http://d.hatena.ne.jp/ritou/20110402/1301679908 --The OAuth 2.0 Authorization Framework: Bearer Token Usage(日本語)~ http://openid-foundation-japan.github.io/rfc6750.ja.html *OAuthの利用例 [#nb5a56c4] **Instagramで共有した写真をFacebookやTwitterにも投稿 [#y50e86a3] Instagramの設定画面から複数の外部サービスと連携するように設定できる。 -InstagramはOAuthを用いて外部サービスに代理投稿するアクセス権限を受け取る。 -すると、Instagramは外部サービスに写真を投稿できるようになる。 -外部サービス --Twitter --Facebook **Facebook Twitter IDでほかのサイトにログイン [#d2a34d61] 「Facebook IDでログイン」や「Twitter IDでログイン」といったボタンで利用されている。 -本来、認証・ID連携のために設計されたものではないが、 --外部サービスにユーザのプロフィール情報を取得するAPIが存在する場合、~ このAPIへのアクセス権限を受け取ることで、認証・ID連携の代替が可能。 --誤った使い方をして脆弱性を生み出しているケースも多い。 -外部サービスの認証を信頼する場合 --Twitter --Facebook *The OAuth 2.0 Authorization Framework [#v698197b] -RFC 6749 - The OAuth 2.0 Authorization Framework~ https://tools.ietf.org/html/rfc6749 -OAuth 2.0 Core & Bearer Spec (RFC 6749 & RFC 6750) 翻訳公開! - OAuth.jp~ http://oauth.jp/blog/2013/01/23/oauth-20-core-bearer-spec-rfc-rfc-6749-rfc-67/ --The OAuth 2.0 Authorization Framework~ http://openid-foundation-japan.github.io/rfc6749.ja.html --The OAuth 2.0 Authorization Framework: Bearer Token Usage(日本語)~ http://openid-foundation-japan.github.io/rfc6750.ja.html **OAuth 2.0のフロー定義 [#kd90c6bf] OAuth 2.0仕様には4つのフローが定義されている。~ これらのフローのタイプを「グラント種別」と呼ばれる。 -IPA ISEC セキュア・プログラミング講座:~ Webアプリケーション編 第8章 マッシュアップ:サーバサイドマッシュアップ~ https://www.ipa.go.jp/security/awareness/vendor/programmingv2/contents/709.html 以下の様な「グラント種別」がある模様。 ***Authorization Codeグラント種別 [#y8bf613e] -RFC 6749 - The OAuth 2.0 Authorization Framework~ 4.1. Authorization Code Grant~ https://tools.ietf.org/html/rfc6749#section-4.1 --Authorization Code Flow +----------+ | Resource | | Owner | | | +----------+ ^ | (B) +----|-----+ Client Identifier +---------------+ | -+----(A)-- & Redirection URI ---->| | | User- | | Authorization | | Agent -+----(B)-- User authenticates --->| Server | | | | | | -+----(C)-- Authorization Code ---<| | +-|----|---+ +---------------+ | | ^ v (A) (C) | | | | | | ^ v | | +---------+ | | | |>---(D)-- Authorization Code ---------' | | Client | & Redirection URI | | | | | |<---(E)----- Access Token -------------------' +---------+ (w/ Optional Refresh Token) Note: The lines illustrating steps (A), (B), and (C) are broken into two parts as they pass through the user-agent. ***Implicitグラント種別 [#h347a7c6] -RFC 6749 - The OAuth 2.0 Authorization Framework~ 4.2. Implicit Grant~ https://tools.ietf.org/html/rfc6749#section-4.2 --Implicit Grant Flow +----------+ | Resource | | Owner | | | +----------+ ^ | (B) +----|-----+ Client Identifier +---------------+ | -+----(A)-- & Redirection URI --->| | | User- | | Authorization | | Agent -|----(B)-- User authenticates -->| Server | | | | | | |<---(C)--- Redirection URI ----<| | | | with Access Token +---------------+ | | in Fragment | | +---------------+ | |----(D)--- Redirection URI ---->| Web-Hosted | | | without Fragment | Client | | | | Resource | | (F) |<---(E)------- Script ---------<| | | | +---------------+ +-|--------+ | | (A) (G) Access Token | | ^ v +---------+ | | | Client | | | +---------+ Note: The lines illustrating steps (A) and (B) are broken into two parts as they pass through the user-agent. ***Resource Owner Password Credentialsグラント種別 [#i2483bc0] -RFC 6749 - The OAuth 2.0 Authorization Framework~ 4.3. Resource Owner Password Credentials Grant~ https://tools.ietf.org/html/rfc6749#section-4.3 --Resource Owner Password Credentials Flow +----------+ | Resource | | Owner | | | +----------+ v | Resource Owner (A) Password Credentials | v +---------+ +---------------+ | |>--(B)---- Resource Owner ------->| | | | Password Credentials | Authorization | | Client | | Server | | |<--(C)---- Access Token ---------<| | | | (w/ Optional Refresh Token) | | +---------+ +---------------+ -補足 --ASP.NET Identityによる認証サイト = Authorization Server に該当する。 --Clientは、Authorization Serverの情報を元に認可をする連携サイト(, システム, アプリ)。 --Resource OwnerはUserIDやPasswordを保持しているユーザやシステム。 -参考 --memo: Force.com : REST API 開発 ユーザ名パスワード OAuth 認証~ http://vaindespair.blogspot.jp/2013/01/blog-post_5252.html ---Understanding the Username-Password OAuth Authentication Flow~ Force.com REST API Developer Guide | Salesforce Developers~ https://developer.salesforce.com/docs/atlas.en-us.api_rest.meta/api_rest/intro_understanding_username_password_oauth_flow.htm ***Client Credentialsグラント種別 [#ka6e3a8f] -RFC 6749 - The OAuth 2.0 Authorization Framework~ 4.3. Resource Owner Password Credentials Grant~ https://tools.ietf.org/html/rfc6749#section-4.4 --Client Credentials Grant +---------+ +---------------+ | | | | | |>--(A)- Client Authentication --->| Authorization | | Client | | Server | | |<--(B)---- Access Token ---------<| | | | | | +---------+ +---------------+ ***RFC 6750 - Bearer Token Usage [#d65223fc] -RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage~ https://tools.ietf.org/html/rfc6750 +--------+ +---------------+ | |--(A)- Authorization Request ->| Resource | | | | Owner | | |<-(B)-- Authorization Grant ---| | | | +---------------+ | | | | +---------------+ | |--(C)-- Authorization Grant -->| Authorization | | Client | | Server | | |<-(D)----- Access Token -------| | | | +---------------+ | | | | +---------------+ | |--(E)----- Access Token ------>| Resource | | | | Server | | |<-(F)--- Protected Resource ---| | +--------+ +---------------+ *OAuth 2.0のフロー [#e2a0d0ab] **Authorization Code Flow [#u3db1d50] ***Step 0:Client Registration [#m875246b] 準備 -クライアント登録の方法についてはOAuthの仕様では定められていない。 -OAuth Clientは、OAuth Serverに対してアプリ名やドメインなどを添えて自身を登録。 -通常はOAuth Serverのデベロッパー向けサイトでOAuth Clientを登録する。 -Consumer KeyとConsumer Secret? ***Step 1:Initiate [#gdaa4c60] Flowの開始 -「Facebook IDでログイン」や「Twitter IDでログイン」といったボタンで開始する。 -OAuth ClientがResource OwnerからAPIアクセス権限の付与を受ける。 -OAuth 1.0とOAuth 2.0とでフローは多少異なる。 ***Step 2:Authorization Request [#vc5a8f68] ユーザ認証とアクセス権限付与のリクエスト -事前にOAuth ClientはOAuth Serverにアクセスし、未認可のRequest Tokenを取得する。 -OAuth ClientはClient識別情報を付与しResource OwnerをOAuth Serverにリダイレクト -どのようなClient識別情報が付与されるかは、OAuth 1.0とOAuth 2.0で異なる。 --OAuth 2.0:Request Token --OAuth 2.0:Client識別情報をclient_idパラメータに含める。 ***Step 3:Authenticate User & Get Approval [#i686ca48] ユーザ認証とアクセス権限付与 -リダイレクトを受けたOAuth Serverは --ユーザを認証(OAuthの仕様には含まれない)する(Request Tokenを認可済にする)。 --ユーザが使用するOAuth ClientにOAuth Serverへのアクセス権限付与を許可する。 ***Step 4:Authorization Response [#g8be73c7] ユーザ認証とアクセス権限付与の結果をレスポンス -OAuth ServerはResource OwnerをOAuth Clientにリダイレクトして戻す。 -リダイレクトURLには、アクセス権限を示すトークンが含まれる。 --OAuth 1.0では、認可済Request Token --OAuth 2.0では、Client特性により、2種類のトークン形式が存在する。 ---Web : code ---Native : access_token ***Step 5:Obtain Access Token [#v305cf48] -OAuth 1.0 :~ Request Tokenを実際のアクセス権を示すAccess Tokenと交換する -OAuth 2.0 :~ Step 4でaccess_tokenを得ていない場合、~ 受け取った「アクセス権限を示すトークン」とAccess Tokenを交換。 ***Step 6:API Access [#tc7739ce] APIへのアクセス -Access Token使ってAPIにアクセス。 -Access Tokenは期限切れ、無効化されるまで利用可能。 *セキュリティ [#v33a7e19] セキュリティに関する考察 -OAuth 2.0の概要とセキュリティ~ http://www.slideshare.net/charlier-shoe/oauth-20-29540466 **Authorization Codeグラント種別 [#f4d89342] ***Open Redirector [#ycb0a43b] -第3回 Webセキュリティのおさらい~ その3 CSRF・オープンリダイレクト・クリックジャッキング:~ JavaScriptセキュリティの基礎知識|gihyo.jp … 技術評論社~ http://gihyo.jp/dev/serial/01/javascript-security/0003?page=2 -対策 --Server は、redirect_uri は事前登録必須 + 完全一致にする。 ***Covert Redirect [#gc1850ca] 既知の問題点を組み合わせた攻撃手法。 以下の2つが組み合わさって成立する。 -Server 側の甘めの redirect_uri 検証 -Client 側が内包する open redirector -OAuth 2.0 の脆弱性 (!?) "Covert Redirect" とは - OAuth.jp~ http://oauth.jp/blog/2014/05/07/covert-redirect/ --[[前述の対策を行う。>#ycb0a43b]] --Client は、state パラメータをチェックする。 state パラメタとは、 -OAuth 2.0のstateとredirect_uriとOpenID ConnectのnonceとID Tokenについて - r-weblife~ http://d.hatena.ne.jp/ritou/20121008/1349695124 --CSRF対策のトークンをワンタイムにしたら意図に反して脆弱になった実装例 - 徳丸浩の日記(2011-01-27)~ http://www.tokumaru.org/d/20110127.html ザックリ言って、 -推奨される -CSRF対策の -推測困難な文字列 --(ワンタイム性は必須ではない) と言うモノらしい。 **Implicitグラント種別 [#c9029c4e] 「OAuth 2.0 の implicit grant flow を認証に使うと、車が通れる程どてかいセキュリティ・ホールが開く。」らしい。 この、セキュリティ・ホールとは、 -単なる OAuth 2.0 を認証に使うと、~ 車が通れるほどのどでかいセキュリティー・ホールができる | @_Nat Zone~ https://www.sakimura.org/2012/02/1487/ ザックリ言って、 -攻撃者の構築したRP(A)は、access_tokenを収集する。 -攻撃者は、 access_token 置換え攻撃により、~ RP(B)にログイン(若しくはRP(B)経由でリソース・アクセス)できる。 と言うモノらしい。 この問題に対しては、 -OAuth 2.0 Implicit Flowをユーザー認証に利用する際のリスクと対策方法について #idcon - r-weblife~ http://d.hatena.ne.jp/ritou/20120206/1328484575 --Idcon11 implicit demo~ http://www.slideshare.net/ritou/idcon11-implicit-demo 以下のように対策できる。 -Implicit Flowを利用している場合、Authorization Code Flowを利用できないか確認する。 -認可サーバーがアクセストークンが発行された対象のクライアントを確認できるAPIを提供する。~ これにより、アクセストークン置き換え攻撃を検知できる(RFCに定義はないので独自実装する)。 -OpenID ConnectのID Tokenを利用する。 **Resource Owner Password Credentialsグラント種別 [#jf8e8e73] HTTPSはホスト名の部分だけ情報として渡し、~ 以後のパスやクエリストリング情報は暗号化される。 従ってGETでも一応安全だが、 -アクセスログに残る -ブラウザの履歴に残る -リファラーに残る という問題がある。 従って、このグラント種別では、 -基本的に、Browserから実行させてはいけない。 -また、Webサーバで、W3Cログ等を出力させないようにする。 などが必要になると考える。 IISならW3Cログの出力をカスタマイズできる。 -参考 --HTTPSとQueryString ---security - Secure Oauth 2.0 Resource Owner Password Credentials Grant Type - Stack Overflow~ http://stackoverflow.com/questions/39129331/secure-oauth-2-0-resource-owner-password-credentials-grant-type ---httpsでqueryStringは安全か | Rutakeの技術メモ~ http://cloudfront.rutake.com/techmemo/2011/01/26/https%E3%81%A7querystring%E3%81%AF%E5%AE%89%E5%85%A8%E3%81%8B/ --QueryStringのログ出力 ---logging - Does IIS7 log request query string by default? - Stack Overflow~ http://stackoverflow.com/questions/19918561/does-iis7-log-request-query-string-by-default ---Does IIS log query strings in a https request? : The Official Microsoft IIS Forums~ https://forums.iis.net/t/1178176.aspx **参考 [#bc772000] ***OAuth 2.0 and the Road to Hell [#y1f5c2c5] -OAuth 1.0 のほうが OAuth 2.0 より安全なの? - Qiita~ http://qiita.com/TakahikoKawasaki/items/3600b28af7b63671b968 --「OAuth 2.0 は OAuth 1.0 よりも安全ではない」とは言えない。 --OAuth 1.0 でクライアントアプリケーションを作る方こそ安全ではない。 --OAuth 1.0 ではなく OAuth 2.0 を採用するのが良い。 ***Inspecting access tokens [#sace68e4] -OAuth2.0の備忘録的まとめ - Ari-Press~ http://www.ari-hiro.com/blog/2012/12/30/oauth2-summary --Manually Build a Login Flow - Facebook Login~ https://developers.facebook.com/docs/facebook-login/manually-build-a-login-flow/v2.4 *参考 [#sd7d7875] **OAuth 1.0 [#b6b38b34] -OAuth Core 1.0~ http://oauth.net/core/1.0/ -OAuth - Wikipedia~ https://ja.wikipedia.org/wiki/OAuth#OAuth_2.0 -ゼロから学ぶOAuth:特集|gihyo.jp … 技術評論社~ http://gihyo.jp/dev/feature/01/oauth --第1回 OAuthとは?―OAuthの概念とOAuthでできること~ http://gihyo.jp/dev/feature/01/oauth/0001 --第2回 OAuth Consumerの実装(入門 : OAuth Access Tokenの取得と利用)~ http://gihyo.jp/dev/feature/01/oauth/0002 --第3回 OAuth Consumerの実装(応用 : smart.fm APIおよびGoogle Data APIsの利用)~ http://gihyo.jp/dev/feature/01/oauth/0003 --第4回 OAuth Service Providerの実装~ http://gihyo.jp/dev/feature/01/oauth/0004 **OAuth 2.0 [#q09835d5] -デジタル・アイデンティティ技術最新動向 連載インデックス - @IT~ http://www.atmarkit.co.jp/fsecurity/index/index_digid.html --デジタル・アイデンティティ技術最新動向(1):「OAuth」の基本動作を知る - @IT ---http://www.atmarkit.co.jp/ait/articles/1208/27/news129.html ---http://www.atmarkit.co.jp/ait/articles/1208/27/news129_2.html -OAuth 2.0でWebサービスの利用方法はどう変わるか - @IT --http://www.atmarkit.co.jp/fsmart/articles/oauth2/01.html --http://www.atmarkit.co.jp/fsmart/articles/oauth2/02.html --http://www.atmarkit.co.jp/fsmart/articles/oauth2/03.html -色々な OAuth のフローと doorkeeper gem での実装 - Qiita~ http://qiita.com/tyamagu2/items/5aafff7f6ae0a9ec94aa -OpenID Connect 入門 〜コンシューマーにおけるID連携のトレンド〜~ OAuth 2.0 Authorization Code Flow~ http://www.slideshare.net/kura_lab/openid-connect-id/21 -OAuth 2.0 の Response Type 全パターン - OAuth.jp~ http://oauth.jp/blog/2015/01/06/oauth2-multiple-response-type/