OAuthãããã³ã«ã®ä¸èº«ããã£ãã解説ãã¦ã¿ãã
ããã¼ãã¼ã£ãã£!ã
ã¦ãªãã£ã¦ãTwitterã®APIã®BASICèªè¨¼ã6ææ«ã«çµäºãã¦OAuth/xAuthã«ç§»è¡ããã¨ãããã®ææã«ãããããã¦OAuthã«ã¤ãã¦åå¼·ãã¦ã¿ããã§ãã®ã?
OAuthèªè¨¼ãå©ç¨ããã©ã¤ãã©ãªã¯åè¨èªã§åºããã£ã¦ãã¦ãã®ã§ããã使ãã°ããããã¾ãã? ã¨ããã¨è©±ãçµããã®ã§ãããããã®ã©ã¤ãã©ãªã®ä¸èº«ã¯ãªã«ãã£ã¦ãã®ãã£ã¦ãã¨ããOAuthããScalaã®ã©ã¤ãã©ãªä½ããªãã調ã¹ããã¨ãã¾ã¨ãã¦ã¿ã¾ããã
ééã£ã¦ããã¨ãããããã¨æãã®ã§ããã³ãæè¿ã§ãï¼ï¼
OAuthã£ã¦ãããããªããªã®?
ãã®ããããã£ããã¨ããã¨ãAPIå©ç¨å´ããã¦ã¼ã¶èªè¨¼ãAPIæä¾ãµã¼ãã¹å´ã«ãã£ã¦ãããããã®ä»æ§ãã£ã¦æãã§ãããã?
BASICèªè¨¼ã®å ´åãAPIå©ç¨å´ãèªè¨¼ã«å¿ è¦ãªã¢ã«ã¦ã³ãããã¹ã¯ã¼ããé ããå¿ è¦ãããããã§ããæªæã®ããAPIå©ç¨å´ãããªãã¨ãã¡ã¼ã«ã¼ãã¨ãããã¤ãã£ãã¼ã®ã¢ã«ã¦ã³ããå©ç¨ãããµã¼ãã¹ããBASICèªè¨¼ãç¨ãã¦å®è£ ããå ´åããã®ããªãã¨ãã¡ã¼ã«ã¼ãã使ãã¦ã¼ã¶ã¼ã®IDã¨ãã¹ã¯ã¼ããå ¥åããã¦ããµã¼ãã¼ä¸ã®ãã¼ã¿ãã¼ã¹ã«ä¿åãã¦ããã¦ã¢ã«ã¦ã³ããããã¯ããã¨ãåºæ¥ã¡ããããã§ã(ã¤ã³ã¿ã¼ãããããã)ã
ã¤ã¾ããBASICèªè¨¼ã¯IDããã¹ã¯ã¼ãã䏿çã«ããAPIå©ç¨å´ã«é ãããã¦ãã¾ãã¨ããåé¡ã§ãã
ãããåé¿ããããã«ãã¢ã«ã¦ã³ãã®èªè¨¼å¦çèªä½ãã¤ãã£ãã¼ãªã©APIæä¾å´ã«ä»£ããã«ãã£ã¦ããããAPIå©ç¨å´ã¯èªè¨¼ãããçµæã ãããããã¨ããå½¢ã«ããã®ãOAuthã§ãã
å³ã«ããã¨ãããªæãã§ããService Provider(Provider)ã¯ãã¤ãã£ãã¼ã4sqãªã©ã®APIæä¾å´ãOAuth Consumer(Consumer)ã¯ãOAuthã§Providerã«èªè¨¼ãã¦ããã£ã¦APIãå¼ã³åºãå´(ä¾ãã°ãµãã¼ã£ãã¼)ãUserã¯ãå®éã®ã¢ã«ã¦ã³ããæã£ã¦ãã人ã§ã(ããã¯ãããªãã§ã!)ã
OAuthã§ã¯ãã¢ã«ã¦ã³ãèªè¨¼ã§IDããã¹ã¯ã¼ããå ¥åããç®æã¯ã¤ãã£ãã¼ãªã©Providerã®ãã¼ã¸ã«éå®ããã¾ãã®ã§ãæªæã®ããConsumerãIDãã¹ã¯ã¼ããçããã¨ãã§ããªããªãã¾ãã
èªè¨¼ã®ãã£ããããæé
OAuthèªè¨¼ã®è©³ããããã¼ã¯ここã¨ãここã¨ããåèã«ãã¦ãããããã®ã§ããããã£ãã説æããã¨ãããªæãã§ãã
ã¾ãã¯ãäºåæºåã¨ãã¦Consumerã®ç»é²ãå¿ è¦ã§ãã
- Consumerç»é²
- é常ã¯ãäºåã«Providerã«Consumerç»é²ããã¦ããã¾ãã
- ç»é²ããã¨ãConsumer Keyã¨Consumer Secretãçºè¡ããã¾ãã
- Consumer Keyã¨Consumer Secretã¯ã以éã®OAuthèªè¨¼ã§ä½¿ç¨ãã¾ã
ããããããå®éã®OAuthèªè¨¼ã®æµãã§ãã
- ã¦ã¼ã¶ã¯ãConsumerã«OAuthèªè¨¼ãè¡ãããã«æç¤ºãã¾ãã
- é常ã¯ãConsumerã®ãã¼ã¸ã«ãããã°ã¤ã³ãã¿ã³ãªã©ãã¯ãªãã¯ãã¾ãã
- Consumerã¯ãProviderãããªã¯ã¨ã¹ããã¼ã¯ã³ãåå¾ãã¾ã
- ConsumerããProviderã¸Httpéä¿¡ã§ãªã¯ã¨ã¹ããã¼ã¯ã³ãè¦æ±ãã¾ãã
- ãªã¯ã¨ã¹ããã¼ã¯ã³ã®è¦æ±ã§ãäºåã«çºè¡ããã¦ããConsumer Keyã¨ããªã¯ã¨ã¹ããã©ã¡ã¼ã¿ãConsumer Secretã§ç½²åããå¤ããã©ã¡ã¼ã¿ã¨ãã¦ä»ä¸ãã¾ãã
- Providerã¯Httpã®ã¬ã¹ãã³ã¹ã¨ãã¦ãªã¯ã¨ã¹ããã¼ã¯ã³ãè¿ãã¾ãããã®æ®µéã§ã¯ãã¾ã èªè¨¼ã¯å®äºãã¦ãã¾ããã
- èªè¨¼ç¨URLã¸ã®ãªãã¤ã¬ã¯ãã»ã¦ã¼ã¶æ¿èª
- Consumerã¯ãçºè¡ããããªã¯ã¨ã¹ããã¼ã¯ã³ãURLã«ä»ä¸ãã¦ãProviderã®èªè¨¼ç¨URLã¸ãªãã¤ã¬ã¯ããè¡ãã¾ãã
- ãªãã¤ã¬ã¯ãå ã§ãProviderãã¦ã¼ã¶ã«å¯¾ãã¦ãConsumerãè¦æ±ãã¦ããOAuthèªè¨¼ã«ããAPIå©ç¨ã許å¯ããã鏿ãã¾ãã
- æ¿èªããå ´åã¯ãProviderã¯(é常ã¯)Consumerç»é²æã«è¨å®ããã³ã¼ã«ããã¯URLã¸ãªãã¤ã¯ã¬ããã¾ãã
- ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®åå¾
- ã³ã¼ã«ããã¯URLã¸ã®ãªãã¤ã¬ã¯ãã§ãConsumerã¯ãªã¯ã¨ã¹ããã¼ã¯ã³ããã¨ã«ã¢ã¯ã»ã¹ãã¼ã¯ã³åå¾ãHttpéä¿¡ã§Providerã¸è¦æ±ãã¾ã
- ã¢ã¯ã»ã¹ãã¼ã¯ã³åå¾è¦æ±ã¯ãConsumer Keyã¨ãªã¯ã¨ã¹ããã¼ã¯ã³ãªã©ããã©ã¡ã¼ã¿ã«ä»ä¸ãã¦å¼ã³åºãã¾ãã(é常ã¯Authorizationãããã«è¨å®)
- ã¢ã¯ã»ã¹ãã¼ã¯ã³åå¾è¦æ±ã®ãã©ã¡ã¼ã¿ããConsumer Secretã§ç½²åããå¤ãä»ä¸ãã¾ãã
- Providerã¯ãã¬ã¹ãã³ã¹ã¨ãã¦ã¢ã¯ã»ã¹ãã¼ã¯ã³ãè¿ãã¾ãã
- OAuthã§ã®APIå¼ã³åºã
- å®éã®APIå¼ã³åºãã¯ãåå¾ããã¢ã¯ã»ã¹ãã¼ã¯ã³ããã©ã¡ã¼ã¿ã«ä»ä¸ãã¦å¼ã³åºãã¾ãã
- ã¢ã¯ã»ã¹ãã¼ã¯ã³ã¨Consumer Keyãããã³ãã©ã¡ã¼ã¿ãConsumer Secretã§ç½²åããå¤ããAuthorizationãããã«è¨å®ã«è¨å®ãã¦APIãå¼ã³åºããã¨ã§ãOAuthèªè¨¼ãå©ç¨ããAPIå¼ã³åºããã§ãã¾ãã
ãã£ããå³ã«ããã¨ãããªæãã§ãããã?
ã¾ã¨ãã¾ãã
- APIãå©ç¨ããå´ã¯ãConsumerã¨ãã¦äºåç»é²ãã¦Consumer Keyã¨Consumer Secretãåå¾ãã¦ãã
- OAuthã§APIå¼ã³åºãããã«ã¯ã¢ã¯ã»ã¹ãã¼ã¯ã³ãå¿ è¦
- ã¢ã¯ã»ã¹ãã¼ã¯ã³ã¯ãProviderå´ã§ã¦ã¼ã¶ã¼ããªã¯ã¨ã¹ããã¼ã¯ã³ãæ¿èªãããã¨ã§çºè¡ãããã
- ãªã¯ã¨ã¹ããã¼ã¯ã³ã¯ãConsumerãProviderã«HTTPéä¿¡ã§çºè¡ãä¾é ¼ãã
- ãªã¯ã¨ã¹ããã¼ã¯ã³ãProviderããåå¾ããããProviderã®èªè¨¼ãã¼ã¸ã¸ãªãã¤ã¯ã¬ããã¦ã¦ã¼ã¶ã«æ¿èªãã¦ããã
- ã¦ã¼ã¶ãæ¿èªããããConsumerã®ã³ã¼ã«ããã¯URLã¸ãªãã¤ã¯ã¬ããããã®ã§ãããã§ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®çºè¡ãConsumerããProviderã¸ä¾é ¼ãã
- Consumerã¯ãããã£ãã¢ã¯ã»ã¹ãã¼ã¯ã³ãAuthorizationãããã«ã¤ãã¦APIãå¼ã³åºããã¨ã§OAuthèªè¨¼ä¸ã§ã®APIã³ã¼ã«ãã§ãã
OAuthã®èªè¨¼ããAPIå¼ã³åºãã¾ã§
ããããå®éã®OAuthèªè¨¼ããAPIå¼ã³åºãã¾ã§ã®éã«ãConsumer/Provider/Userã®3è éã§ã©ã®ãããªããã¨ããè¡ããã¦ããã®ã解説ãã¾ããã
0.Consumerç»é²
ã¾ãã¯ãProviderã«OAuthãå©ç¨ããConsumerã§ãããã¨ãç»é²ãã¾ããConsumerãç»é²ããéã«è¨å®ããã³ã¼ã«ããã¯URLããã2.èªè¨¼ç¨URLã¸ã®ãªãã¤ã¬ã¯ãã»ã¦ã¼ã¶æ¿èªãã§ã¦ã¼ã¶ãæ¿èªå¾ã«Providerãããªãã¤ã¬ã¯ããããURLã«ãªãã¾ãã
TwitterのConsumer登録ページ
foursquereのConsumer登録ページ
Consumerç»é²ãè¡ãã¨ãConsumer Keyã¨Consumer Secretã¨ããäºã¤ã®å¤ãçºè¡ããã¾ãã
Consumer Keyã¯ãã1.ãªã¯ã¨ã¹ããã¼ã¯ã³ã®åå¾ããã3.ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®åå¾ããã4.APIå¼ã³åºããã®å¼ã³åºããªã©ãOAuthã«é¢ããå ¨ã¦ã®Providerã¸ã®ãªã¯ã¨ã¹ãã§å¿ è¦ã¨ããããã©ã¡ã¼ã¿ã§ãããã°Consumerã®IDã«ãªãã¾ãã
Consumer Secretã¯ãOAuthéä¿¡ã§éä¿¡ãããã©ã¡ã¼ã¿ãæ¹ç«ããã¦ããªãã確èªããããã®ç½²åãçæããããã«å¿
è¦ãªãããã°ç§å¯éµã§ãã
ç½²åã«é¢ãã¦ã¯ãã9.ãªã¯ã¨ã¹ãã®ç½²åãã§è§£èª¬ãã¾ãã
1.ãªã¯ã¨ã¹ããã¼ã¯ã³ã®åå¾
OAuthèªè¨¼ã¯ãConsumerãããªã¯ã¨ã¹ããã¼ã¯ã³ã®çºè¡ãProviderã¸è¦æ±ããã¨ããããå§ã¾ãã¾ãã
ãªã¯ã¨ã¹ããã¼ã¯ã³ã®çºè¡è¦æ±ã¯ããªã¯ã¨ã¹ããã¼ã¯ã³çºè¡ç¨ã®Providerå´ã®URLã¸é常HTTP POSTãéä¿¡ãããã¨ã§è¡ãã¾ãã
ããã§ãOAuthãã©ã¡ã¼ã¿ã¨ãã¦ã以ä¸ã®ãããªå¤ãè¨å®ãã¾ãã
| oauth_Consumer_key | Consumerç»é²æã«çºè¡ãããConsumer Key |
|---|---|
| oauth_timestamp | ãªã¯ã¨ã¹ã使æã®ã¿ã¤ã ã¹ã¿ã³ãå¤ |
| oauth_nonce | ãªã¯ã¨ã¹ãæ¯ã«ä¸æãªå¤ãé常ã¯ããç§ãè¨å® |
| oauth_signature | éä¿¡ããURLããã©ã¡ã¼ã¿ãªã©ãæ¹ç«ããã¦ããªãã確èªããããã«Consumerå´ã§çæãããå¤ãé常ã¯HMAC-SHA1ã§Consumer Secretãå ã«ãã¤ã¸ã§ã¹ããçæãBase64ã§ã¨ã³ã³ã¼ãããã詳ããã¯ã9.ãªã¯ã¨ã¹ãã®ç½²åããåç §ã |
| oauth_signature_method | oauth_signatureãçæããç½²åæ¹å¼ãé常ã¯HMAC-SHA1ã ããPLAINTEXTããµãã¼ãããProviderããã |
| oauth_version | å¿ é ã§ã¯ãªãããè¨å®ããå ´åã¯1.0ã§ããå¿ è¦ããã |
ãããã®ãã©ã¡ã¼ã¿ããHttpãããã®Authorizationãããã«ã¤ãã¦POSTãã¾ããå
·ä½çãªãªã¯ã¨ã¹ããããã®ä¸èº«ã¯ãããªæãã§ãã
POST /oauth/request_token HTTP/1.1 Authorization: OAuth oauth_consumer_key=XXXX&oauth_nonce=1111&oauth_signature=YYYY=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=9999
ãªããAuthorizationãããã§ã¯ãªãPOSTã®Bodyã«è¨å®ãã¦ãOKãªå ´åãããã¾ãã
ãã¦ããã®POSTã®ã¬ã¹ãã³ã¹ã¨ãã¦ãProviderå´ããã¬ã¹ãã³ã¹ããã£ã«ãªã¯ã¨ã¹ããã¼ã¯ã³ã®å¤ãè¨å®ããã¦è¿ããã¾ãã
oauth_token=XYZABCD&oauth_token_secret=ZZZZZ
| oauth_token | ããããªã¯ã¨ã¹ããã¼ã¯ã³ã®å¤ |
|---|---|
| oauth_token_secret | ãªã¯ã¨ã¹ããã¼ã¯ã³æ¯ã«çºè¡ãããå¤ãã¢ã¯ã»ã¹ãã¼ã¯ã³çºè¡æã®ç½²åã¯ãã®å¤ãå«ãããã¼ã«ããçæããå¿ è¦ãããã詳ããã¯ã9.ãªã¯ã¨ã¹ãã®ç½²åããåç §ã |
ããã¾ã§ã§ãªã¯ã¨ã¹ããã¼ã¯ã³ã®åå¾ãçµããã¾ããã
2.èªè¨¼ç¨URLã¸ã®ãªãã¤ã¬ã¯ãã»ã¦ã¼ã¶æ¿èª
ãªã¯ã¨ã¹ããã¼ã¯ã³ãåå¾ã§ããããProviderã®èªè¨¼ç¨URLã¸ãªãã¤ã¯ã¬ããã¾ãã
é常ã®Webãµã¼ãã¹ã§ã¯ãã¦ã¼ã¶ã®OAuthèªè¨¼ãã¿ã³ã®ã¯ãªãã¯æã«ãªã¯ã¨ã¹ããã¼ã¯ã³ãåå¾ãã¦ããã®ã¬ã¹ãã³ã¹ã¨ãã¦ã¦ã¼ã¶ã®ãã©ã¦ã¶ã«Providerã®èªè¨¼ç¨URLã¸ãªãã¤ã¯ã¬ããè¿ãå½¢ã«ãªãã§ãããã
Providerã®èªè¨¼ç¨URLã¸ã¯ããªã¯ã¨ã¹ããã¼ã¯ã³ãURLãã©ã¡ã¼ã¿ã«å«ããURLã§ã®ãªãã¤ã¬ã¯ãã«ãªãã¾ãããã¨ãã°ã"http://foursquare.com/oauth/authorize?oauth_token=XYZABCD"ã®ãããªå½¢ã§ãã
ãªãã¤ã¬ã¯ãå ã®Providerã¯ããã®Consumerããã®OAuthèªè¨¼è¦æ±ãã¦ã¼ã¶ãæ¿èªããã確èªãããã¼ã¸ãè¿ãã¾ããfoursquerã®å ´åã¯ãããªç»é¢ã§ãã
ãã®ç»é¢ã§æ¿èªãè¡ãã¨ãProviderã¯ãããããConsumerç»é²æã«è¨å®ããã¦ããURLã¸ãªãã¤ã¯ã¬ããè¡ãã¾ãããã®ã¨ãã«ãã©ã¡ã¼ã¿ã¨ãã¦ãªã¯ã¨ã¹ããã¼ã¯ã³ã®å¤ã¨ãå ´åã«ãã£ã¦ã¯oauth_verifierã¨ããå¤ãä»ä¸ããã¾ãã
ãããªæãã®URLã«ãªãã¾ãã
http://fooservice.com/?oauth_token=XYZABC&oauth_verifier=NNNNNN
3.ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®åå¾
ãã¦ããªãã¤ã¬ã¯ããåããConsumerã¯ãæ¿èªããããªã¯ã¨ã¹ããã¼ã¯ã³ãå ã«ã¢ã¯ã»ã¹ãã¼ã¯ã³ãProviderããåå¾ãã¾ãããã®ã¢ã¯ã»ã¹ãã¼ã¯ã³ãç¡ãã¨ãAPIã®å¼ã³åºããã§ãã¾ããã
ã¢ã¯ã»ã¹ãã¼ã¯ã³ãããªã¯ã¨ã¹ããã¼ã¯ã³ã¨åãããã«Provideræå®ã®URLã¸HTTPéä¿¡ãè¡ããã¨ã§åå¾ã§ãã¾ãã
OAuthãã©ã¡ã¼ã¿ã¨ãã¦ã以ä¸ã®ãããªå¤ãAuthorizationãããã«è¨å®ãã¾ãã
| oauth_token | ã¦ã¼ã¶ãæ¿èªæ¸ã¿ã®ãªã¯ã¨ã¹ããã¼ã¯ã³ |
|---|---|
| oauth_verifier | ãªã¯ã¨ã¹ããã¼ã¯ã³ãæ¿èªãããæã«ããããoauth_verifierã®å¤ |
| oauth_consumer_key | Consumerç»é²æã«çºè¡ãããConsumer Key |
| oauth_timestamp | ãªã¯ã¨ã¹ã使æã®ã¿ã¤ã ã¹ã¿ã³ãå¤ |
| oauth_nonce | ãªã¯ã¨ã¹ãæ¯ã«ä¸æãªå¤ãé常ã¯ããç§ãè¨å® |
| oauth_signature | éä¿¡ããURLããã©ã¡ã¼ã¿ãªã©ãæ¹ç«ããã¦ããªãã確èªããããã«Consumerå´ã§çæãããå¤ãé常ã¯HMAC-SHA1ã§Consumer Secretãå ã«ãã¤ã¸ã§ã¹ããçæãBase64ã§ã¨ã³ã³ã¼ãããã詳ããã¯ã9.ãªã¯ã¨ã¹ãã®ç½²åããåç §ã |
| oauth_signature_method | oauth_signatureãçæããç½²åæ¹å¼ãé常ã¯HMAC-SHA1ã ããPLAINTEXTããµãã¼ãããProviderããã |
| oauth_version | å¿ é ã§ã¯ãªãããè¨å®ããå ´åã¯1.0ã§ããå¿ è¦ããã |
ãªã¯ã¨ã¹ããã¼ã¯ã³çºè¡æã®ãã©ã¡ã¼ã¿ã«ãããã¦ãoauth_tokenã¨oauth_verifierã追å ããã¦ãã¾ãã
å ·ä½çãªHTTPãªã¯ã¨ã¹ããããã¯ãããªæãã§ãã
POST /oauth/access_token HTTP/1.1 Authorization: OAuth oauth_consumer_key=XXXX&oauth_nonce=1111&oauth_signature=YYYY=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=9999&oauth_token=XYZABC&oauth_verifier=NNNNNN
Providerå´ã®ã¬ã¹ãã³ã¹ããåæ§ã«ã¬ã¹ãã³ã¹ããã£ã«ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®å¤ãè¨å®ããã¦ãã¾ãã
oauth_token=EFGHIJ&oauth_token_secret=WWWWW
| oauth_token | ãããã¢ã¯ã»ã¹ãã¼ã¯ã³ã®å¤ |
|---|---|
| oauth_token_secret | ã¢ã¯ã»ã¹ãã¼ã¯ã³æ¯ã«çºè¡ãããå¤ã以éã®APIå¼ã³åºãæã«ã¯ããã®å¤ãå«ãããã¼ã«ããç½²åãçæããå¿ è¦ãããã詳ããã¯ã9.ãªã¯ã¨ã¹ãã®ç½²åããåç §ã |
ããã§ããããOAuthã§APIãå¼ã³åºãæºåãã§ãã¾ããã
4.APIå¼ã³åºã
OAuthèªè¨¼ä¸ã§ã®APIå¼ã³åºãã¯ãã¢ã¯ã»ã¹ãã¼ã¯ã³ãªã©ã®OAuthé¢é£ã®ãã©ã¡ã¼ã¿ãAuthorizationãããã«è¨å®ããããã§ãé常ã®APIã®ã³ã¼ã«ã¨åæ§ã«è¡ãã¾ãã
OAuthèªè¨¼ã¨Basicèªè¨¼ã®APIå¼ã³åºãã®éãã¯ãAuthorizationãããã®éãã¨è¨ã£ã¦ããããã¨æãã¾ãã
ä¾ãã°ãfoursquerã®checkinsã¨ããAPIå¼ã³åºãã®ãªã¯ã¨ã¹ããããã¯ä»¥ä¸ã®ããã«ãªãã¾ãã
GET /v1/checkins HTTP/1.1 Host: api.foursquare.com Authorization: OAuth oauth_consumer_key=XXXX&oauth_nonce=1111&oauth_signature=YYYY=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=9999&oauth_token=XYZABC&oauth_verifier=NNNNNN
å
·ä½çã«ãAuthorizationãããã«è¨å®ããå¤ã¯ä»¥ä¸ã®éãã§ãã
| oauth_token | ã¢ã¯ã»ã¹ãã¼ã¯ã³ã®å¤ã |
|---|---|
| oauth_consumer_key | Consumerç»é²æã«çºè¡ãããConsumer Key |
| oauth_timestamp | ãªã¯ã¨ã¹ã使æã®ã¿ã¤ã ã¹ã¿ã³ãå¤ |
| oauth_nonce | ãªã¯ã¨ã¹ãæ¯ã«ä¸æãªå¤ãé常ã¯ããç§ãè¨å® |
| oauth_signature | éä¿¡ããURLããã©ã¡ã¼ã¿ãªã©ãæ¹ç«ããã¦ããªãã確èªããããã«Consumerå´ã§çæãããå¤ãé常ã¯HMAC-SHA1ã§Consumer Secretãå ã«ãã¤ã¸ã§ã¹ããçæãBase64ã§ã¨ã³ã³ã¼ãããã詳ããã¯ã9.ãªã¯ã¨ã¹ãã®ç½²åããåç §ã |
| oauth_signature_method | oauth_signatureãçæããç½²åæ¹å¼ãé常ã¯HMAC-SHA1ã ããPLAINTEXTããµãã¼ãããProviderããã |
| oauth_version | å¿ é ã§ã¯ãªãããè¨å®ããå ´åã¯1.0ã§ããå¿ è¦ããã |
9.ãªã¯ã¨ã¹ãã®ç½²å
æå¾ã«ãããã¾ã§Providerã¸ã®éä¿¡æã«å¿ ãä»ä¸ããå¿ è¦ããã£ãããªã¯ã¨ã¹ãã®ç½²åã®çææ¹æ³ã解説ãã¾ãã
ã¶ã£ã¡ãããここè¦ã¦ãããã®ãæ©ããã§ããã¾ãè»½ãæ¸ãã¦ã¿ã¾ãã
ç½²åæ¹å¼ã¯ãé常ã¯ãHMAC-SHA1ã¨ããæ¹å¼ã§ãã
ç½²åã¯ã(A)Consumer Secretåã³Token Secretãããã¼ã¨ãã¦ãã(B)HTTPã¡ã½ãããURLãå ¨ã¦ã®ãã©ã¡ã¼ã¿ãé£çµããæååããå ã«ä½æããããã¤ã¸ã§ã¹ãå¤ã§ãã
ã¾ãã(A)Consumer Secretåã³Token Secretãã®ç½²åãã¼ã§ããã以ä¸ã®å½¢å¼ã®æååããã¼ã¨ãã¾ãã
"Consumer SecretãURLã¨ã³ã³ã¼ãããå¤"&"Token Secretã®å¤"
Consumer Secretã¯Consumerç»é²æã«Providerããçºè¡ãããå¤ãToken Secretã¯ããªã¯ã¨ã¹ããã¼ã¯ã³ãã¢ã¯ã»ã¹ãã¼ã¯ã³ãçºè¡ãããã¨ãã«Providerã®HTTPã¬ã¹ãã³ã¹ããã£ã«å«ã¾ããå¤ã§ãã
Consumer Secret=XXXXã§TokenSecretãNNNNã®å ´åã¯ããã¼ã¯"XXXX&NNNN"ã§ãã
ã1.ãªã¯ã¨ã¹ããã¼ã¯ã³ã®åå¾ãã®æç¹ã§ã¯Token Secretã¯ã¾ã ç¡ãã®ã§ãConsumer Secretã®ã¿ã§ç½²åãã¼ãä½ãã¾ãã"XXXX&"ã®ããã«ãªãã¾ãã
次ã«ã(B)HTTPã¡ã½ãããURLãå ¨ã¦ã®ãã©ã¡ã¼ã¿ãé£çµããæååãã«ã¤ãã¦ã§ãã
"(a)HTTPã¡ã½ãã"&"(b)ã¢ã¯ã»ã¹ããURL"&"(c)å ¨ã¦ã®ã¯ã¨ãªãã©ã¡ã¼ã¿ããã¼ã®æé ã§ã½ã¼ããURLã¨ã³ã³ã¼ãããå¤"
(a)HTTPã¡ã½ããã¯ãGET/POSTãªã©ã§ãã(b)ã¯å®éã«ã¢ã¯ã»ã¹ããURL(http://foursquare.com/oauth/request_token ãªã©)ã§ãã
(c)å ¨ã¦ã®ã¯ã¨ãªãã©ã¡ã¼ã¿ããã¼ã®æé ã§ã½ã¼ããURLã¨ã³ã³ã¼ãããå¤ã«ã¤ãã¦ã¯ãOAuthãã©ã¡ã¼ã¿ãå«ãå ¨ã¦ã®ãã©ã¡ã¼ã¿(APIã³ã¼ã«æã®ãã©ã¡ã¼ã¿ãå«ã)ãããã¼ã®æé ã«ã½ã¼ãããä¸ã§"ãã¼1=å¤1&ãã¼2=å¤2..."ã®ããã«&ã§çµåãã¾ãã
ä¾:
param1=value1¶m2=value2&oauth_consumer_key=XXXX&oauth_nonce=1111&oauth_signature=YYYY=&oauth_signature_method=HMAC-SHA1&oauth_timestamp=9999&oauth_token=XYZABC&oauth_verifier=NNNNNN
æå¾ã«ã(a)ã¨(b)ã¨(c)ãããããURLã¨ã³ã³ã¼ããã¦"&"ã§çµåãã¾ããããã§ã§ããæååãç½²å対象ã§ãã
ä¾:
POST&http:%3A%2F%2Ffoursquare.com%2Foauth%2Frequest_token¶m1=value1%3param2=value2%3oauth_consumer_key=XXXX%3oauth_nonce=1111%3oauth_signature=YYYY=%3oauth_signature_method=HMAC-SHA1%3oauth_timestamp=9999%3oauth_token=XYZABC%3oauth_verifier=NNNNNN
å®éã®ç½²åã¯(A)ç½²åãã¼ããã¨ã«(B)ç½²å対象æååããHMAC-SHA1ã¢ã«ã´ãªãºã ãå©ç¨ãã¦16é²ã®ãã¤ã¸ã§ã¹ãå¤ãçæãããã®å¤ãBase64ã¨ã³ã³ã¼ããã¾ããããã«ãURLã¨ã³ã³ã¼ãããæååãç½²åã¨ãã¦oauth_signatureã®å¤ã«ãªãã¾ãã
å®éã«çæãããã®ãããã§ãã
8bP1EEnRivY3cDkYHcqaLN7+wRM=
Scalaã§OAuthã©ã¤ãã©ãªæ¸ãã¦ã¿ã
ã¦ãã¨ã¼ãã£ããã§ãã
yuroyoro-util/src/main/scala/com/yuroyoro/util/net/OAuth.scala at master · yuroyoro/yuroyoro-util · GitHub
Scalaã§ã¯ãDispatchã¨ããã®ãããã¾ãã
Dispatch — Dispatch






