Coder Social home page Coder Social logo

piotrj / doorkeeper-provider-app Goto Github PK

View Code? Open in Web Editor NEW

This project forked from doorkeeper-gem/doorkeeper-provider-app

1.0 2.0 0.0 117 KB

An example OAuth 2 provider application using the Doorkeeper gem, Rails and Devise

Home Page: http://doorkeeper-provider.herokuapp.com/

Ruby 98.43% JavaScript 1.57%

doorkeeper-provider-app's Introduction

Doorkeeper Provider App

This app is an example of an OAuth 2 provider using doorkeeper, Rails 3.1 and Devise. Check out the app hosted on heroku for a live demo and documentation details.

Installation

First clone the repository from GitHub:

git clone git://github.com/applicake/doorkeeper-provider-app.git

Install all dependencies with:

bundle install

After that you're almost ready to go.

Configuration

The configuration is quite simple, all you need to do is run:

bundle exec rake db:setup

This will generate all necessary tables, create fake data, create an user and a client application.

The user email is [email protected] and password is doorkeeper.

The application id and secret will show up on terminal when the script ends.

After that, you can just fire up the rails server.

API

This app also provides a sample JSON API under /api/v1. This API is only available via OAuth so if you want to create a client application, check out app's documentation or follow this Sinatra example for more details.

The current API endpoints are:

/api/v1/profiles.json
/api/v1/me.json

In routes.rb you can check out how they're made:

namespace :api do
  namespace :v1 do
    resources :profiles
    get '/me' => "credentials#me"
  end
end

We namespace the API controllers to avoid name clashing and collisions between your existing application and the API. This way you can make your API stable while changing the behavior of your app.

You can find all controllers under /app/api/v1 folder.

The api_controller.rb works as a parent class to the other controllers. It only defines a method that returns the current resource owner, based on the access token:

def current_resource_owner
  User.find(doorkeeper_token.resource_owner_id) if doorkeeper_token
end

Require access token

To make your API only available for OAuth users, you need to tell doorkeeper to require an access token in your controller, like this:

module Api::V1
  class ProfilesController < ApiController
    doorkeeper_for :all # require access token in all actions
    respond_to     :json

    def index
      respond_with Profile.all
    end
  end
end

If you access this resource without an access token, you'll get an 401 Unauthorized response status.

doorkeeper-provider-app's People

Contributors

felipeelias avatar

Stargazers

 avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.