Permalink
Browse files

Pimping my app

  • Loading branch information...
piotrj committed Nov 29, 2011
1 parent 35dd571 commit 8d5197d267ceb27875974d34dff8b57589a895e8
@@ -7,3 +7,14 @@
//= require jquery
//= require jquery_ujs
//= require_tree .
+
+$(function() {
+ $('[data-explore]').click(function() {
+ var link = $(this);
+ link.button('loading');
+ $('#display-json').load(link.attr('href'), function() {
+ link.button('reset');
+ });
+ return false;
+ });
+});
@@ -3,5 +3,13 @@
* and any sub-directories. You're free to add application-wide styles to this file and they'll appear at
* the top of the compiled file, but it's generally better to create a new file per style scope.
*= require_self
- *= require_tree .
-*/
+ *= require_tree .
+*/
+
+body {
+ padding: 60px;
+}
+
+section > .row {
+ margin-bottom: 10px;
+}
@@ -0,0 +1,8 @@
+class ApiController < ApplicationController
+ respond_to :json
+
+ def explore
+ @json = doorkeeper_access_token.get("api/v1/#{params[:api]}").parsed
+ respond_with @json
+ end
+end
@@ -1,3 +1,11 @@
class ApplicationController < ActionController::Base
protect_from_forgery
+
+ def doorkeeper_oauth_client
+ @client ||= OAuth2::Client.new(DOORKEEPER_APP_ID, DOORKEEPER_APP_SECRET, :site => DOORKEEPER_APP_URL)
+ end
+
+ def doorkeeper_access_token
+ @token ||= OAuth2::AccessToken.new(doorkeeper_oauth_client, current_user.doorkeeper_access_token) if current_user
+ end
end
@@ -1,9 +1,17 @@
-- if current_user
- %p
- You are logged in as user with doorkeeper id
- = current_user.doorkeeper_uid
- = link_to "Log out", destroy_user_session_path
-- else
- %p
- You are not logged in
- = link_to "Log in with doorkeeper provider", user_omniauth_authorize_path(:doorkeeper)
+%section
+ .row
+ .span16
+ - unless signed_in?
+ %h3 Sign in first to explore the provider's API
+ %p= link_to "Sign in with OAuth 2 provider", user_omniauth_authorize_path(:doorkeeper), :class => "btn primary"
+ - else
+ %h2 Explore the api
+ .well
+ = link_to "My Credentials", explore_api_path(:me, :format => :json), :class => "btn", "data-explore" => []
+ = link_to "Profiles", explore_api_path(:me, :format => :json), :class => "btn", "data-explore" => []
+ = link_to "Sign out", destroy_user_session_path, :class => "btn primary"
+
+ %p
+ %pre#display-json
+ Select one of the api methods above
+
@@ -1,9 +1,16 @@
!!! 5
%html
%head
- %title DoorkeeperDeviseClient
+ %title Doorkeeper Oauth Client (Devise + Omniauth)
+ = stylesheet_link_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap.min.css"
= stylesheet_link_tag "application"
- = javascript_include_tag "application"
= csrf_meta_tags
%body
- = yield
+ .topbar
+ .fill
+ .container
+ = link_to "Doorkeeper Oauth Client (Devise + Omniauith)", root_path, :class => "brand"
+ .container
+ = yield
+ = javascript_include_tag "application"
+ = javascript_include_tag "http://twitter.github.com/bootstrap/1.4.0/bootstrap-buttons.min.js"
View
@@ -48,6 +48,8 @@
# You can have the root of your site routed with "root"
# just remember to delete public/index.html.
+ #
+ match 'explore/:api' => 'api#explore', :as => :explore_api
devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" } do
get 'sign_out', :to => 'users/sessions#destroy', :as => :destroy_user_session
end

0 comments on commit 8d5197d

Please sign in to comment.