Sie sind auf Seite 1von 3

a59583234c8025e6126c4cdf34c22cd0a18e4fe4f8d2badc6c940ddcd1e6238e

#Client creation
client = OAuth2::Client.new('e8a719740a6e4a871e180abc558d32178ae6d614951d6f1d61f
ab2d578df1414', '874cde4e4c6aa413a0f38208c3138a39efdd65905f571fd7f3d7a2657bcc182
2', site: "http://localhost:3000")
// test access token - student
304d8b16895e78adf714825601e5510c4789827ee5919a520bac40ee84187bcc
//test server access token - trainer
cf3773133eb061632b5215a5bf3a79a87e8a29cf9dfba63afb2e4f323263b0bc
////local client creation data
client = OAuth2::Client.new('c1fe47dbf9cf765b38c542efac71df091a0ac74c100f425a21c
3f28d6496a2ff', 'a61e67c383d8dbf5dc966e2ac99d6a5d5d0e473a91aca20c21a29352fa67b7d
7', site: "http://localhost:3000")
//samsung localhost
client = OAuth2::Client.new('372b2b62df3f543421014ea864dc72e1b30cb339f933f36413a
f9c3423f8e5f4', '60ddd43423b2ccfa4ff05c0dd909e39dd079978ee0b9c2b2fc330ce92484da7
d', site: "http://localhost:3000")
//samsung localhost student access token
ca8ca2110c9fa191b8a4343026afa84d7fa29f30d8fb60e28536113f11fd7619
///local access token - student
2e3e694d6ba4c7aade1eb2bc91f1222c219752fbf2fa6eb0e9c8aa749f231679
//local access token - student1
86d3b3e2a13667bf54bf0119197ca8798aae7a8a44b815aa60b2734c5605db67
//local access token - student3
a6ebcceaeb5b412aea85603c3c49589c233af085933d20249f9f41caf69d9778
///local access token - trainer1
e3eae2b7b3134866c063eb5226cac42cbef71fb917829a32fdb90c727e7bc903
////dev client creation data
client = OAuth2::Client.new('06e255e69a08ed4cb69148448797dc0622f957a3e8603f4ef22
d7c50d23fb403', '2efb1ebf8a85001fff2c85b573dc36e853a285782f6fe7c6666976617aca7c5
d', site: "http://projectskydev.lakesidelab.com")
//dev access token
0e4900c7def5eabecb7637d3fd84804c241d96375b4060182cd0de4e14b5bd94
#authorize url (optional)
client.auth_code.authorize_url(redirect_uri: "http://www.google.com")
#redirect_url (static)
http://localhost:3000/oauth/authorize?response_type=code&client_id=f9e8179f476fa
f9290a18b535099f5d740d3e0c3b9e60ddec40b247546875c74&redirect_uri=http%3A%2F%2Fww
w.google.com

#access token creation


access = client.auth_code.get_token('3821ad0d7fc17e6833f2ff95ab3655fc638f2d8c5e1
68a3d923edb1ba925b1a1', redirect_uri: "http://www.google.com")
credential auth
access = client.password.get_token('student@sky.com', 'password')
http://stackoverflow.com/questions/11724912/posting-in-oauth-with-client-credent
ials-with-doorkeeper
Restclient methods
require 'rest-client'
require 'json'
client_id = 'my_client_id...'
client_secret = 'my_client_secret...'
response = RestClient.post 'http://projectsky.lakesidelab.com/oauth/token', {
grant_type: 'password',
client_id: client.id,
client_secret: client.secret,
username: 'trainer@sky.com',
password: 'password'
}
token = JSON.parse(response)["access_token"]
# this line works great:
RestClient.get 'http://localhost:3000/api/v1/flights.json', { 'Authorization' =>
"Bearer #{token}" }
# this line always fails (401 Unauthorized):
RestClient.post 'http://localhost:3000/api/v1/flights.json', { 'Authorization' =
> "Bearer #{token}" }

RestClient.post 'http://localhost:3000/api/v1/flights.json', {}, { 'Authorizatio


n' => "Bearer #{token}" }
#data api
access.post('/api/v1/data.json', params: { datum: { data_identifier: 'sample_ide
ntifier', data: 'sample_data', version: '1.0'}).parsed
#institution api
access.post('/api/v1/institutions.json', params:{ institution: { name: 'new_inst
itution_xavier1', location: 'test location', contact_info: {
contact_person: 'shajith', email: 'shajith@user.com'}, license_info: { expiry_du
ration: '10 months', classes: { class1: {class: '2', tablets: '3'}, class2: {cla
ss: '2', tablets: '5'}}}}}).parsed

RestClient.post 'http://projectsky.lakesidelab.com/api/v1/institutions.json', {
institution: { name: 'new_institution_xavier1', location: 'test location'}}, { '
Authorization' => "Bearer #{token}" }
RestClient.post 'http://localhost:3000/api/v1/institutions.json', { institution:
{ name: 'new_institution_xavier1', location: 'test location'}}, { 'Authorizatio
n' => "Bearer #{token}" }
RestClient.post 'http://localhost:3000/api/v1/data.json', { datum: { data: 'new_
institution_xavier1', data_identifier: { id: 'test location' }, version: '1.0' }
}, { 'Authorization' => "Bearer #{token}" }

response = RestClient.post 'http://localhost:3000/oauth/token', {


grant_type: 'password',
client_id: client.id,
client_secret: client.secret,
username: 'student@sky.com',
password: 'password'
}

Das könnte Ihnen auch gefallen