-
Notifications
You must be signed in to change notification settings - Fork 1
Home
Dipil Saud edited this page Apr 14, 2015
·
2 revisions
Welcome to the omniauth-khan-academy wiki! Khan academy API reference: http://api-explorer.khanacademy.org/
#Using the authenticated Khan API
###Store auth credentials
In the auth callback controller (default is routed to */auth/khan_academy/callback
), store the khan token and password.
E.g. if your User model has :khan_token, :khan_password
auth_hash = request.env["omniauth.auth"]
user.khan_token = auth_hash[:credentials][:token]
user.khan_password = auth_hash[:credentials][:secret]
user.save
###Example authenticated request
oauth_consumer = OmniAuth::Strategies::KhanAcademy.new(Rails.application, CONSUMER_TOKEN, CONSUMER_SECRET).consumer
access_token = OAuth::AccessToken.new(oauth_consumer, user.khan_token, user.khan_password)
access_token.get('/api/v1/user/exercises')
#Using the unauthenticated Khan API
oauth_consumer = OmniAuth::Strategies::KhanAcademy.new(Rails.application, CONSUMER_TOKEN, CONSUMER_SECRET).consumer
access_token = OAuth::AccessToken.new(oauth_consumer)
access_token.get('/api/v1/exercises')