Module: XHP::HealthPlanet::OAuth
Defined Under Namespace
Classes: RequestToken, Scope
Instance Method Summary
collapse
Methods included from XHP::HTTP
#get, #post
Instance Method Details
#get_auth_url(redirect_uri = 'https://www.healthplanet.jp/success.html', scope = Scope.new, response_type = 'code') ⇒ Object
65
66
67
68
69
|
# File 'lib/xhp.rb', line 65
def get_auth_url(redirect_uri = 'https://www.healthplanet.jp/success.html',
scope = Scope.new,
response_type = 'code')
"https://www.healthplanet.jp/oauth/auth?client_id=#{CLIENT_ID}&redirect_uri=#{redirect_uri}&scope=#{scope.to_s}&response_type=#{response_type}"
end
|
#token(code, redirect_uri = 'https://www.healthplanet.jp/success.html', grant_type = 'authorization_code') ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/xhp.rb', line 71
def token(code,
redirect_uri = 'https://www.healthplanet.jp/success.html',
grant_type = 'authorization_code')
url = "https://www.healthplanet.jp/oauth/token.?client_id=#{CLIENT_ID}&client_secret=#{CLIENT_SECRET}&redirect_uri=#{redirect_uri}&code=#{code}&grant_type=#{grant_type}"
res = post(url)
raise "OAuth Token API return response code #{res.code}" unless res.code == '200'
json = JSON.parse(res.body)
RequestToken.new(json['access_token'], json['expires_in'], json['refresh_token'])
end
|