Giter VIP home page Giter VIP logo

doorkeeper-provider-app's Introduction

Doorkeeper Provider App

CI

This app is an example of an OAuth 2 provider using Doorkeeper gem, Rails 7.x and Devise.

About Doorkeeper Gem

For more information about the gem, documentation, wiki and another resources, check out the project on GitHub

Installation

First clone the repository from GitHub:

git clone [email protected]:doorkeeper-gem/doorkeeper-provider-app.git

Install all dependencies with:

bin/bundle install

After that you're almost ready to go.

Configuration

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

bin/rails db:setup

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

Seed data

The generated 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 bin/rails server and you're ready to go.

OAuth Endpoint

The endpoints is mounted under /oauth so our routes look like this:

GET       /oauth/authorize
POST      /oauth/authorize
DELETE    /oauth/authorize
POST      /oauth/token
resources /oauth/applications

Example API

This app provides a sample JSON API under /api/v1. 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 changes to your application without messing up with the API's behavior.

You can find all controllers under /app/controllers/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

This is required if you want to return data based on the current user, like in credentials_controller.rb

Make Access Token Required

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

module Api::V1
  class ProfilesController < ApiController
    before_action :doorkeeper_authorize!

    def index
      render json: Profile.recent
    end
  end
end

However, see also the Doorkeeper wiki article about using scopes.

If you attempt to access any of the protected resources without an proper access token, you'll get an 401 Unauthorized response.

Client applications

You can manage all client applications in /oauth/applications.

doorkeeper-provider-app's People

Contributors

biske avatar brntbeer avatar bunnymatic avatar darkaico avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar felipeelias avatar mathias-eco avatar mtancoigne avatar nbulaj avatar piotrj avatar sbusso avatar tachyons avatar wbreeze avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

doorkeeper-provider-app's Issues

redirect_url inconsistency with doorkeeper-devise-client

After installing both doorkeeper-provider-app (and running db:setup) and doorkeeper-devise-client, I'm start getting The redirect uri included is not valid. after authentication.

The solution is simple to go to /oauth/applications and to change http://localhost:3000/callback, which I've set up before based on initial setup, to http://localhost:3000/users/auth/doorkeeper/callback

I can't find this stuff mentioned in documentation, so maybe some initial setup is wrong.

Seed Data

I was looking at the Seed Data instructions to see if I could bypass using the Application interface, as it's broken with Rails 4.2 (doorkeeper-gem/doorkeeper#494).

The website says this:

The generated 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 and you're ready to go.

When is this generated? I ran db:setup and saw no output. I ran rake -T and saw no doorkeeper tasks.

I'm a little wet around the ears with Rails sure, but this seems like a bit of a disconnect.

How should I go about creating applications?

Is this project abandoned?

The app seems pretty behind the latest doorkeeper gem. Is it still maintained? There are also a few (quite old) unmerged PRs.

Error: bundle exec rake db:setup


*****/doorkeeper-provider-app>bundle exec rake db:setup
rake aborted!
cannot load such file -- sqlite3/sqlite3_native
*****/doorkeeper-provider-app/config/application.rb:7:in `'
*****//doorkeeper-provider-app/Rakefile:5:in `require'
*****/doorkeeper-provider-app/Rakefile:5:in `'
(See full trace by running task with --trace)

get token wout redirection

When I try to send

client = OAuth2::Client.new('the_client_id', 'the_client_secret', :site => "http://doorkeeper-provider.herokuapp.com")
access_token = client.password.get_token('[email protected]', 'sekret')

I set valid data as in web but itreturns me an error OAuth2::Error with the html view to signin.

<html>
...
 <form accept-charset="UTF-8" action="/users/sign_in" class="user_new" id="user_new" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="&#x2713;" /><input name="authenticity_token" type="hidden" value="nzP5UzWrFkNhfYDPbhXGyZOnSNtoX6U1c8BbDKUEkIQ=" /></div>
  <div class="clearfix">
    <label for="user_email">Email</label>
    <div class="input">
      <input id="user_email" name="user[email]" size="30" type="email" value="" />
    </div>
  </div>
and so on..

Container image not buildable

Hi all,

i just checked out the code and tried to build the container image using

$ docker build -t doorkeeper .

First issue i ran into:

#8 0.596 Warning: the running version of Bundler (2.0.1) is older than the version that created the lockfile (2.2.21). We suggest you upgrade to the latest version of Bundler by running `gem install bundler`.

After changing Dockerfile from

RUN gem install bundler:2.0.1

to

RUN gem install bundler:2.2.21

i could get rig of the warning but ran into the next issue:

#10 0.525 Your Ruby version is 2.6.5, but your Gemfile specified 3.1.0

So i finally change Dockerfile from

FROM ruby:2.6.5

to

FROM ruby:3.1.0

to get a successful build.

If you agree i'll send a PR to fix this.

Kind regards

RuntimeError in Doorkeeper::ApplicationsController#create

Your path has not been found. Didn't you mean to call routes.oauth_application_url in doorkeeper configuration blocks?

app/controllers/doorkeeper/applications_controller.rb:20:in `create'

This error happens when I try to create a new application.

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.