SlideShare a Scribd company logo
1 of 52
Download to read offline
Oauth2.0を学んだついでにOpenID
Connect とか認証と認可を調べた時の
話
Shunsuke Mihara 

2014/3/31
※2014/03に勉強会した時の内容で
す。googleのAPIコンソールのUI等、
2016/02時点で異なります。
自己紹介
• 最近はすっかりmacずいてます。
(macBookAir,macBook
Pro,iPhone)
• APIに関しては仕事で利用する
事が多かったので、色々興味あ
ります。
• 読書する本の電子書籍化の波が
半端無くおしよせています。
まず最初に
認証と認可の違いの話をします。
認証
ユーザのアイデンティ、つまり「ユーザが自分自身が何者
であると主張しているか」を検証するプロセス。
例えば、ID/パスワードで認証するようなシステムだと、
ログインIDでアイデンティティを判別し、パスワードでそ
の妥当性を判断する
Authentication
認可
何らかの行為を行う際に、当該ユーザにその権限があるの
かどうかを検証するプロセス。
認証したからと言って全ての権限を与えるのではなく、そ
の中の機能の一部のみ利用できるする際には必要。
Authorization
本日は、認証としては
「OpenID connect」,
認可としては
「Oauth2.0」
の話をします。
本日話すこと
1. Oauth2.0の話
2. OpenID Connectの話
3. OpenID Connectの実装(動作を見せます)
1. Oauth2.0の話
Oauthでできる事
API提供サービス(googleとか)の
パスワードを知らなくても、
API利用サービスは提供APIを
利用できちゃいます
→API利用サービスのユーザーは、安心して利用できる。
API提供サービス(googleとか)の
一部の機能だけを、
API利用サービスは提供APIを
利用できちゃいます
→API利用サービスのユーザーは、安心して利用できる。
極端な一例(Oauthが無い場
合)
• とあるサービスで、googleカレンダー連携するために、
googleのIDとパスワードとか、渡して大丈夫かしら
ん?
• googleで色々管理しているから、もしもこれを悪用さ
れたらgoogleDocs見られたら、機密情報丸見えだ
し、写真もアップしてるから、プライベートが流出しそ
う。
極端な一例(Oauthが無い場
合)
• とあるサービスで、googleカレンダー連携するために、
googleのIDとパスワードとか、渡して大丈夫かしら
ん?
• googleで色々管理しているから、もしもこれを悪用さ
れたらgoogleDocs見られたら、機密情報丸見えだ
し、写真もアップしてるから、プライベートが流出しそ
う。
• →怖いから使わないでおこう!
極端な一例(Oauthがある場
合)
• とあるクラウドサービスで、googleカレンダー連携す
るけど、gmailのパスワードは必要無いらしい。
• googleで色々管理しているけど、あのサービスができ
る事といったら、カレンダー見たり、書き込みするくら
い。googleドキュメントとか、プライベートの写真と
か見られる心配なし。
極端な一例(Oauthがある場
合)
• とあるクラウドサービスで、googleカレンダー連携す
るけど、gmailのパスワードは必要無いらしい。
• googleで色々管理しているけど、あのサービスができ
る事といったら、カレンダー見たり、書き込みするくら
い。googleドキュメントとか、プライベートの写真と
か見られる心配なし。
• →よっしゃ、いけてるからガンガン使おう!
WEBサービス(API)でパスワー
ドによる認証認可がいまいちな理由
• 信用の無いサイト場合、パスワードを渡したくない。
• パスワードを気軽に渡す文化が醸造されることによる、長期的
な悪い影響。
• パスワードを適切に保管するコストと責任が発生する。
• 認可の取り消しが困難→パスワード変更位しか取消手段が無い
• そもそもパスワードを持っていない可能性がある。
Oauth2.0のプロトコル概要
今回は複数ある認可フローの中
から、「認可コード」の説明
• 「認可コード」(というフロー名)はサーバーサイド
WEBアプリに最適なタイプです。
• それ以外にも、「クライアントサイドwebアプリ」に最
適化されたもの、APIプロバイダ自身がアプリを作ると
きに最適化されたもの、アプリケーション自身の所有す
るリソース(例:Amazon S3にデータを保存する)
に最適化されたものがあります。
アクセストークン
• Oauthを使う時の目標は基本的に、

「Oauthアクセストークンを取得して、ユーザもしくは
アプリ自身のために、そのアクセストークンを使ってAPI
リクエストを実行する事」

です。
• アクセストークンを取得すれば、そこで認可されたリク
エストは実行できることになります。
• 今日は、アクセストークンを取得するあたりの話をします。
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
https://accounts.google.com/o/oauth2/auth
?client_id=XXX
&redirect_uri=http://fueltest.centos63.com/google/callback
&scope=https://www.googleapis.com/auth/calendar
&response_type=code
&approval_prompt=force
&access_type=offline
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
リダイレクトURIに、GETで認可コードが渡される。
https://example.com/callback?code=CCCCCCCC
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
認可コードとアクセストー
クンを交換する
https://
accounts.google.com/o/
oauth2/token
POST:
client_id=XXXXXX
client_secret=AAAAAA
code=CCCCCCCCC
grant_type=authorizatio
n_code
redirect_uri=http://∼
開始
認可コード要求
ユーザ アプリ  認可サーバ  エンドポイント
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
アクセストークン要求
アクセストークン返却
処理要求
処理返却
{
“access_token”:”xxxxxxxxxxx”,
“token_type” : “Bearer”,
“expire_in” : 3600,
“refresh_token”:”aaaaaaaaaaaaaa”
}
Oauth準備(google)編①
Oauth準備(google)編②
Oauth準備(google)編③
Oauthの認可を取消す
ここからは、認証の話…
2. OpenID Connectの話
2014/02/27
OpenID Connectの
API標準技術仕様が
ローンチされました!!!
OpenID Foundation
理事長:崎村さん曰く
• TCP/IP参照モデルで、業務アプリケーションとアプリ
ケーション層に「アイデンティティ層」を作るイメージ











• google、microsoft、salesforce、sisco、
VMware、Forgeockなど、様々な対応
※
↑ http://www.sakimura.org/2014/02/2277/
OpenIDで何ができるのか?
OpenID provider
(googleとかfacebookとかmixiと
か)
のIDを使って、サービスにログイン
することができます
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却
https://accounts.google.com/o/oauth2/auth
?client_id=XXX
&redirect_uri=http://fueltest.centos63.com/google/callback
&scope=openid(+email)
&response_type=code
&approval_prompt=force
&access_type=online
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却リダイレクトURIに、GETで認可コードが渡される。
https://example.com/callback?code=CCCCCCCC
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却
認可コードとIDトークン
を交換する
https://
accounts.google.com/o/
oauth2/token
POST:
client_id=XXXXXX
client_secret=AAAAAA
code=CCCCCCCCC
grant_type=authorizatio
n_code
redirect_uri=http://∼
開始
認可コード要求
ユーザ アプリ  認可サーバ
ログイン画面&認可画面
ログイン&認可を許可
認可コード返却
IDトークン要求
IDトークン返却
{
"access_token" : “ya29.1.AADtN_VyFt[略]”,
"token_type" : "Bearer",
"expires_in" : 3600,
"id_token" : "eyJhbGciO[略]"
}
IDトークン
• JWT(JSON Web Token )というフォーマットで
帰ってきます。
• eyJhbGciOiJS[略].eyJpc3MiOiJ[略].C_3JU0K
si9[略]みたいなフォーマットです。
• $idTokenArray = explode(".", $idToken);

$idTokenBodyArray =
json_decode(base64_decode($idTokenArr
ay['1']),true);
IDトークンのデコード結果
IDトークンのデコード結果
この2つで
ユーザは
一意になる
3. OpenID Connectの実装(動作を見せます)
OpenIDの実装例
(実際のコードを動かします)
以上です。
ご清聴ありがとうございました。
出典
• O'Reilly Japan OAuth 2.0をはじめよう
• OpenID Connect 101 @ OpenID TechNight
vol.11(http://sssslide.com/
www.slideshare.net/matake/technight11)
• google及び各種公式サイト

More Related Content

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

Oauth2.0とか(認証と認可)_201403