The source for both the provider and the consumer are available here
Screencasts
I have created screencasts to go along with this tutorial. This is my first attempt at screencasting, so please drop me a message if you find them useful or if there is anything you think can be improved. Your feedback is appreciated.
Change the following in views/oauth/oauth2_authorize.html.erb
1
<p>Wouldyouliketoauthorize<%= link_to @token.client_application.name,@token.client_application.url %> (<%=link_to@token.client_application.url,@token.client_application.url%>) to access your account?</p>
To
views/oauth/oauth2_authorize.html.erb
1
<p>Wouldyouliketoauthorize<%= link_to @client_application.name,@client_application.url %> (<%=link_to@client_application.url,@client_application.url%>) to access your account?</p>
You should now start a rails server and navigate to http://localhost:3000/users/sign_up, after signing up go to http://localhost:3000/oauth_clients and create a client. Please not that your client callback_url must match that of the one passed through in your app. If you are using the demo sinatra app, it should be http://localhost:4567/auth/test
There are a couple things you should change in views/oauth_clients/index.html.erb Change the @tokens block to:
require'sinatra'require'oauth2'require'json'enable:sessionsdefclientOAuth2::Client.new(consumer_key,consumer_secret,:site=>"http://localhost:3000")endget"/auth/test"doredirectclient.auth_code.authorize_url(:redirect_uri=>redirect_uri)endget'/auth/test/callback'doaccess_token=client.auth_code.get_token(params[:code],:redirect_uri=>redirect_uri)session[:access_token]=access_token.token@message="Successfully authenticated with the server"erb:successendget'/yet_another'do@message=get_response('data.json')erb:successendget'/another_page'do@message=get_response('data.json')erb:anotherenddefget_response(url)access_token=OAuth2::AccessToken.new(client,session[:access_token])JSON.parse(access_token.get("/api/v1/#{url}").body)enddefredirect_uriuri=URI.parse(request.url)uri.path='/auth/test/callback'uri.query=niluri.to_send
You can grab the required views from consumer/views