">mixi Developer Center (mDC)

mixi Apps

mixi Apps (English) » Technical Specification » PC » RESTful API for PC » Access with 2-legged Oauth Signature to RESTful API

Access with 2-legged Oauth Signature to RESTful API

The appropriate signature with 2-legged OAuth is required for access to RESTful PIs in a mixi App.

Preparation for Signature

oauth_consumer_key Consumer_key issued previously
oauth_nonce Random strings (it should be unique for each request)
oauth_signature Signature validating API requests
oauth_signature_method HMAC-SHA1
oauth_timestamp UNIX timestamp
oauth_version 1.0
xoauth_requestor_id (for PC) Viewer ID
(for mobile) opensocial_ownerid received as request parameter

How to Generate OAuth Signature

The following describes how to generate OAuth Signature for the access to RESTful API. Currently, only HMAC-SHA1 is supported for the signature method.

First of all, three values have to be prepared:

  1. HTTP request method (e.g. GET, POST).
  2. The API URL where the request is sent. Any query parameter should not be included.
  3. Various parameters necessary for OAuth. These parameters must be sorted by the alphabetical order.in advance.

For example,

  1. GET
  2. http://api-example.mixi.jp/people/@me/@self
  3. oauth_consumer_key=bc906fac81f581c3c96a&oauth_nonce=5c261539688b2a591aad&oauth_signature_method=HMAC-SHA1&oauth_timestamp=1244636076&oauth_version=1.0&xoauth_requestor_id=12345

Then the base string can be generated by concatenating with ‘&’ after URI escape for the values above.

GET&http%3A%2F%2Fapi-example.mixi.jp%2Fpeople%2F%40me%2F%40self&oauth_consumer_key%3D
bc906fac81f581c3c96a%26oauth_nonce%3D5c261539688b2a591aad%26oauth_signature_method
%3DHMAC-SHA1%26oauth_timestamp%3D1244636076%26oauth_version%3D1.0%26xoauth_requestor_id
%3D12345

The signature is developed by creating a digest value with HMAC-SHA1 from the base string and encode the digest value in BASE64. The common key used in this case is comprised of consumer_secret and a blank Token Secret, concatenated with ‘&’. The consumer_secret is issued when a mixi App is registered.
For instance, if consumer_secret is 79e0a55cde43e7dc86fd1e1366d6b6ac7771db8, the common key becomes 79e0a55cde43e7dc86fd1e1366d6b6ac7771db8&.
The signature, thus, turns out to be.

TmihyproUc02HOh17W0uz++WdYM=

By adding the parameters generated to the authorization header API request can be sent.

GET http://api-example.mixi.jp/people/@me/@self?xoauth_requestor_id=12345
Authorization: OAuth
oauth_consumer_key="bc906fac81f581c3c96a",
oauth_signature_method="HMAC-SHA1",
oauth_signature="TmihyproUc02HOh17W0uz%2B%2BWdYM%3D",
oauth_timestamp="1244636076",
oauth_nonce="5c261539688b2a591aad",
oauth_version="1.0"


Note that the consumer_key and consumer_secret above are samples, and the developer cannot use these values for actual API access.
consumer_secret is a strictly confidential and it must not be disclosed externally under any circumstances.

See OAuth Consumer Request 1.0 Draft 1 for further details.

References

OAuth Consumer Request 1.0 Draft 1
http://oauth.googlecode.com/svn/spec/ext/consumer_request/1.0/drafts/1/spec.html
December 2007.

TOP OF THIS PAGE