Before you begin, obtain an authorization code by using the information you received when registering a new application. If the user is allowed to return back to the client application, the redirect_uri will be used to redirect the user and an authentication code is returned as the code parameter. Log in is required so browser access should be used over command-line tools such as curl.
GET https://biz.conyac.cc/oauth/authorize
code
.Access the following example URL through your browser with your entered parameters:
https://biz.conyac.cc/oauth/authorize?response_type=code&client_id=df256790540e639c9ef7a1debc31ae09405170c5b51b76d4a123b910cc032e56&redirect_uri=https%3A%2F%2Fyourconyacapp.com%2Foauth%2Fconyac%2Fcallback
After logging in, you should be redirected to a URL like the following example:
https://yourconyacapp.com/oauth/conyac/callback?code=daaefad48a50797ff9b424e4ac948dda87bb8238d67090b4fa6909726f235ad3
You will get an access token using the authorization code obtained from above.
POST https://biz.conyac.cc/oauth/token
curl https://biz.conyac.cc/oauth/token \
-d client_id=df256790540e639c9ef7a1debc31ae09405170c5b51b76d4a123b910cc032e56 \
-d client_secret=f11d67fe92e97c371dec524e989ed3289828e604f5c4c4b545e7392dfb47d7a3 \
-d redirect_uri=https%3A%2F%2Fyourconyacapp.com%2Foauth%2Fconyac%2Fcallback \
-d grant_type=authorization_code \
-d code=b35ec927409e96ce3676ccc77e27240a205d4fe5e74d446c34e42e2f5f72c5ca
-X POST
{
"access_token": "a5adb9bc60a9ed4438f7db1443971181b1dab875f0d6994d3245aa4cee7e34b8",
"token_type": "bearer",
"expires_in": null,
"refresh_token": null,
"scope": ""
}
Because Conyac API is implemented with regards to the OAuth 2.0 standard, API access and authentication is possible with
the consumer OAuth 2.0 library that is open to the public. Here is an example of authentication using the oauth2
Ruby gem.
Run the following in irb
require 'oauth2'
callback = "https://yourconyacapp.com/oauth/conyac/callback"
app_id = "df256790540e639c9ef7a1debc31ae09405170c5b51b76d4a123b910cc032e56"
secret = "f11d67fe92e97c371dec524e989ed3289828e604f5c4c4b545e7392dfb47d7a3"
client = OAuth2::Client.new(app_id, secret, site: "https://biz.conyac.cc/")
client.auth_code.authorize_url(redirect_uri: callback)
When the URL is returned, simply copy and paste it to your browser’s address bar.
https://biz.conyac.cc/oauth/authorize?response_type=code&client_id=df256790540e639c9ef7a1debc31ae09405170c5b51b76d4a123b910cc032e56&redirect_uri=https%3A%2F%2Fyourconyacapp.com%2Foauth%2Fconyac%2Fcallback
Since (https://yourconyacapp.com) Web application does not currently exist, please ignore any ‘webpage is not available’ warnings. If you look at your browser’s address bar, you should notice that it has been redirected and you are now at the following URL.
https://yourconyacapp.com/auth/conyac/callback?code=205f705d46ccd7cdc0ea4f7f3db113289291ba8092f7e10586b9b1e2c1fe8e34
Use 205f705d46ccd7cdc0ea4f7f3db113289291ba8092f7e10586b9b1e2c1fe8e34
code to get the access token from irb.
access_token = client.auth_code.get_token('205f705d46ccd7cdc0ea4f7f3db113289291ba8092f7e10586b9b1e2c1fe8e34', redirect_uri: callback)
access_token.token
is the actual access token.
access_token.token
=> "2b0bf9de2146afa09996c2c6b180d69e9d6f1791c39dd169355a32adf3cf389f"