GithubHelp home page GithubHelp logo

doorkeeper-gem / doorkeeper-devise-client Goto Github PK

View Code? Open in Web Editor NEW
81.0 6.0 55.0 451 KB

An example OAuth 2 client for Doorkeeper Provider App using Rails and Devise

Home Page: https://doorkeeper-devise-client.herokuapp.com

Ruby 83.45% JavaScript 1.39% CSS 0.08% HTML 14.38% Dockerfile 0.71%
doorkeeper devise ruby oauth2-client

doorkeeper-devise-client's Introduction

Doorkeeper Devise+Omniauth Client

Build Status

This app is an example of OAuth2 client. It was built in order to test the doorkeeper provider example. It uses rails, devise and omniauth gems. OAuth2 strategy is build on top of abstract OAuth2 strategy for OmniAuth

About Doorkeeper Gem

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

Installation & Configuration

If you want to run the application by yourself here are the steps for you.

First you need to clone the repository from GitHub

git clone [email protected]:doorkeeper-gem/doorkeeper-devise-client.git

Install all the gems

bundle install

And migrate the database

bundle exec rake db:migrate

At this point the application should be ready to run, but it won't communicate correctly with the provider. You need to set up environment variables to indicate the oauth2 provider values. In your .env file, setup these variables

DOORKEEPER_APP_ID = "375c2e3fd..." # ID for your app registered at the provider
DOORKEEPER_APP_SECRET = "6a2fa82ab..." # Secret
DOORKEEPER_APP_URL = "http://the-provider.com" # URL to the provider

If you want to test it out you can use our sample provider using doorkeeper gem. It's available here. In order to add your application and get your application ID and SECRET click here.

Now you are ready to start the app

bundle exec rails s

doorkeeper-devise-client's People

Contributors

adimola4 avatar dependabot-preview[bot] avatar dependabot-support avatar dependabot[bot] avatar felipeelias avatar jordanmaguire avatar kerrizor avatar nachokb avatar nbulaj avatar originalhat avatar piotrj avatar ryan2johnson9 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

doorkeeper-devise-client's Issues

sqlite 1.6.3 requires ruby 2.7 > 2.6

Last week's dependabot upgrade broke the build:

------                                                                                                                                                                                                                                                                
 > [6/8] RUN bundle install --jobs 4:                                                                                                                                                                                                                                 
#0 3.278 Fetching gem metadata from https://rubygems.org/.........                                                                                                                                                                                                    
#0 5.886 sqlite3-1.6.3-x86_64-linux requires ruby version >= 2.7, < 3.3.dev, which is
#0 5.886 incompatible with the current version, ruby 2.6.3p62
------
Dockerfile:12
--------------------
  10 |     COPY Gemfile Gemfile.lock ./
  11 |     
  12 | >>> RUN bundle install --jobs 4
  13 |     
  14 |     COPY . .
--------------------
ERROR: failed to solve: process "/bin/sh -c bundle install --jobs 4" did not complete successfully: exit code: 5

Not found. Authentication passthru.

I started doorkeeper-provider-app on port 3000 and doorkeeper-devise-client on port 4000.
http://localhost:3000/oauth/applications/1 screen is :

image

I click on Authorize button and get the following screen
image

I click again on Authorize to go to client root
image

Now, I click on the button "Sign in with Outh2 provider" and get error message
image

My client side .env file has provider side credentials as follows:
image

So, is there an error in my re_direct uri?

Where to set scopes?

Let's say I protected a method of my app with doorkeeper_for :create, scopes: [:write].

So when the client is asking for authorization, it needs to ask for this scope. How should I do that?

Thanks

Sign Out Button Not Working

Hi

I am using doorkeeper gem and for testing purpose I am using http://doorkeeper-provider.herokuapp.com and http://doorkeeper-devise.herokuapp.com. Once I logged in and clicked on sign out button it returns me to home url.

But if I click on sign in button again, it lands me to user area of http://doorkeeper-devise.herokuapp.com where I can call API's for credentials and profiles, WITHOUT ASKING FOR LOGIN AGAIN.

I am using your doorkeeper gem in my app so please revert m ASAP so that I can test it with client also.

Regards

undefined local variable or method `new_user_session_path' for #<Users::OmniauthCallbacksController:0x0055f3bb2ad758>

Dear good people..
I've been struggling to solve this issue the past few days..

System configuration

PROVIDER (I made it by myself)
according to gem list:

  1. devise (4.5.0)
  2. doorkeeper (5.0.2)
  3. rails (5.1.6)
  4. warden (1.2.7)
  5. I use Ruby 2.5.1 (ruby 2.5.1p57 (2018-03-29 revision 63029) [x86_64-linux])

I only use gem 'doorkeeper' and 'devise' in my gemfile
provider gemfile

CLIENT (pulling from https://github.com/doorkeeper-gem/doorkeeper-devise-client)
according to gem list

  1. devise (1.5.1)
  2. oauth2 (0.5.1)
  3. rails (3.1.3)
  4. warden (1.1.0)
  5. omniauth (1.0.1)
  6. omniauth-oauth2 (1.0.0)
  7. I use Ruby 2.1.0 (ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-linux])

========================================================================

Steps to reproduce

So I click this 'sign in with oauth2 provider' on my doorkeeper-devise-client
client ss

and then it redirect me to
http://localhost:3000/users/sign_in?return_to=%2Foauth%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3De1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A4000%252Fusers%252Fauth%252Fdoorkeeper%252Fcallback
because I haven't log in to my provider yet..

Here is my provider doorkeeper.rb -> config/initializers/doorkeeper.rb
provider doorkeeper

And then after I login, it redirected me to
http://localhost:4000/users/auth/doorkeeper/callback?code=ea6096403e07e657cae1cedb28e5b72ef69783b14ee17ab56fd2102aabe4868d
with error like this
undefined local variable or method `new_user_session_path' for #Users::OmniauthCallbacksController:0x0055f3bb2ad758

the weird thing is if I use 'https://github.com/doorkeeper-gem/doorkeeper-provider-app' as my provider everything work well..

Expected behavior

I should be login to the doorkeeper-devise-client

Log

Here are the log in case you need it
PROVIDER
Started GET "/oauth/authorize?response_type=code&client_id=e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fusers%2Fauth%2Fdoorkeeper%2Fcallback" for 127.0.0.1 at 2018-11-14 10:16:19 +0700
(0.1ms) SELECT "schema_migrations"."version" FROM "schema_migrations" ORDER BY "schema_migrations"."version" ASC
Processing by Doorkeeper::AuthorizationsController#new as HTML
Parameters: {"response_type"=>"code", "client_id"=>"e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0", "redirect_uri"=>"http://localhost:4000/users/auth/doorkeeper/callback"}
Redirected to http://localhost:3000/users/sign_in?return_to=%2Foauth%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3De1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A4000%252Fusers%252Fauth%252Fdoorkeeper%252Fcallback
Filter chain halted as :authenticate_resource_owner! rendered or redirected
Completed 302 Found in 10ms (ActiveRecord: 0.0ms)

Started GET "/users/sign_in?return_to=%2Foauth%2Fauthorize%3Fresponse_type%3Dcode%26client_id%3De1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0%26redirect_uri%3Dhttp%253A%252F%252Flocalhost%253A4000%252Fusers%252Fauth%252Fdoorkeeper%252Fcallback" for 127.0.0.1 at 2018-11-14 10:16:19 +0700
Processing by Devise::SessionsController#new as HTML
Parameters: {"return_to"=>"/oauth/authorize?response_type=code&client_id=e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fusers%2Fauth%2Fdoorkeeper%2Fcallback"}
Rendering devise/sessions/new.html.erb within layouts/application
Rendered devise/shared/_links.html.erb (2.2ms)
Rendered devise/sessions/new.html.erb within layouts/application (160.3ms)
Completed 200 OK in 1312ms (Views: 1302.5ms | ActiveRecord: 0.9ms)

Started POST "/users/sign_in" for 127.0.0.1 at 2018-11-14 10:16:30 +0700
Processing by Devise::SessionsController#create as HTML
Parameters: {"utf8"=>"โœ“", "authenticity_token"=>"Ss52g6c+ohz2P2j8+AXy8qKOEHC5QKLxbg4H+JkzXaytPfQwfVd0m7rOKgNJ3/6mJmr5Ya7RSGkcO2hg1mN69w==", "user"=>{"email"=>"[email protected]", "password"=>"[FILTERED]", "remember_me"=>"0"}, "commit"=>"Log in"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."email" = ? ORDER BY "users"."id" ASC LIMIT ? [["email", "[email protected]"], ["LIMIT", 1]]
Redirected to http://localhost:3000/oauth/authorize?response_type=code&client_id=e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fusers%2Fauth%2Fdoorkeeper%2Fcallback
Completed 302 Found in 359ms (ActiveRecord: 0.4ms)

Started GET "/oauth/authorize?response_type=code&client_id=e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0&redirect_uri=http%3A%2F%2Flocalhost%3A4000%2Fusers%2Fauth%2Fdoorkeeper%2Fcallback" for 127.0.0.1 at 2018-11-14 10:16:30 +0700
Processing by Doorkeeper::AuthorizationsController#new as HTML
Parameters: {"response_type"=>"code", "client_id"=>"e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0", "redirect_uri"=>"http://localhost:4000/users/auth/doorkeeper/callback"}
User Load (0.4ms) SELECT "users".* FROM "users" WHERE "users"."id" = ? ORDER BY "users"."id" ASC LIMIT ? [["id", 2], ["LIMIT", 1]]
Doorkeeper::Application Load (0.3ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."uid" = ? LIMIT ? [["uid", "e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0"], ["LIMIT", 1]]
Doorkeeper::AccessToken Load (0.4ms) SELECT "oauth_access_tokens".* FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."application_id" = ? AND "oauth_access_tokens"."resource_owner_id" = ? AND "oauth_access_tokens"."revoked_at" IS NULL ORDER BY "oauth_access_tokens"."created_at" DESC [["application_id", 2], ["resource_owner_id", 2]]
(0.1ms) begin transaction
Doorkeeper::AccessGrant Exists (0.2ms) SELECT 1 AS one FROM "oauth_access_grants" WHERE "oauth_access_grants"."token" = ? LIMIT ? [["token", "ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc"], ["LIMIT", 1]]
SQL (0.3ms) INSERT INTO "oauth_access_grants" ("resource_owner_id", "application_id", "token", "expires_in", "redirect_uri", "created_at", "scopes") VALUES (?, ?, ?, ?, ?, ?, ?) [["resource_owner_id", 2], ["application_id", 2], ["token", "ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc"], ["expires_in", 600], ["redirect_uri", "http://localhost:4000/users/auth/doorkeeper/callback"], ["created_at", "2018-11-14 03:16:30.722657"], ["scopes", ""]]
(63.0ms) commit transaction
Redirected to http://localhost:4000/users/auth/doorkeeper/callback?code=ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc
Completed 302 Found in 103ms (ActiveRecord: 67.1ms)

Started POST "/oauth/token" for 127.0.0.1 at 2018-11-14 10:16:30 +0700
Processing by Doorkeeper::TokensController#create as /
Parameters: {"grant_type"=>"authorization_code", "code"=>"[FILTERED]", "client_id"=>"e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0", "client_secret"=>"[FILTERED]", "redirect_uri"=>"http://localhost:4000/users/auth/doorkeeper/callback"}
Doorkeeper::AccessGrant Load (0.3ms) SELECT "oauth_access_grants".* FROM "oauth_access_grants" WHERE "oauth_access_grants"."token" = ? LIMIT ? [["token", "ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc"], ["LIMIT", 1]]
Doorkeeper::Application Load (0.2ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."uid" = ? LIMIT ? [["uid", "e1135c4a9a8b8e623279f2483ec729284265a6b8a5c695d7416b35a6eb29f7b0"], ["LIMIT", 1]]
(0.1ms) begin transaction
Doorkeeper::AccessGrant Load (0.2ms) SELECT "oauth_access_grants".* FROM "oauth_access_grants" WHERE "oauth_access_grants"."id" = ? LIMIT ? [["id", 64], ["LIMIT", 1]]
SQL (0.3ms) UPDATE "oauth_access_grants" SET "revoked_at" = ? WHERE "oauth_access_grants"."id" = ? [["revoked_at", "2018-11-14 03:16:30.924931"], ["id", 64]]
Doorkeeper::Application Load (0.2ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
CACHE Doorkeeper::Application Load (0.0ms) SELECT "oauth_applications".* FROM "oauth_applications" WHERE "oauth_applications"."id" = ? LIMIT ? [["id", 2], ["LIMIT", 1]]
Doorkeeper::AccessToken Exists (0.2ms) SELECT 1 AS one FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."token" = ? LIMIT ? [["token", "9ae580adf7d24244119fe7696c348a7df6f70d1dc9f2eb679e904b1dddfcbf4a"], ["LIMIT", 1]]
Doorkeeper::AccessToken Exists (0.1ms) SELECT 1 AS one FROM "oauth_access_tokens" WHERE "oauth_access_tokens"."refresh_token" = ? LIMIT ? [["refresh_token", "b75bba568350dff1e4b5254b83d347c0cea11cbb34e196899f22d78b970b9038"], ["LIMIT", 1]]
SQL (0.2ms) INSERT INTO "oauth_access_tokens" ("resource_owner_id", "application_id", "token", "refresh_token", "expires_in", "created_at", "scopes") VALUES (?, ?, ?, ?, ?, ?, ?) [["resource_owner_id", 2], ["application_id", 2], ["token", "9ae580adf7d24244119fe7696c348a7df6f70d1dc9f2eb679e904b1dddfcbf4a"], ["refresh_token", "b75bba568350dff1e4b5254b83d347c0cea11cbb34e196899f22d78b970b9038"], ["expires_in", 7200], ["created_at", "2018-11-14 03:16:30.965406"], ["scopes", ""]]
(106.7ms) commit transaction
Completed 200 OK in 161ms

Started GET "/api/v1/me.json" for 127.0.0.1 at 2018-11-14 10:16:31 +0700

ActionController::RoutingError (No route matches [GET] "/api/v1/me.json"):

actionpack (5.1.6) lib/action_dispatch/middleware/debug_exceptions.rb:63:in call' web-console (3.7.0) lib/web_console/middleware.rb:135:in call_app'
web-console (3.7.0) lib/web_console/middleware.rb:30:in block in call' web-console (3.7.0) lib/web_console/middleware.rb:20:in catch'
web-console (3.7.0) lib/web_console/middleware.rb:20:in call' actionpack (5.1.6) lib/action_dispatch/middleware/show_exceptions.rb:31:in call'
railties (5.1.6) lib/rails/rack/logger.rb:36:in call_app' railties (5.1.6) lib/rails/rack/logger.rb:24:in block in call'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in block in tagged' activesupport (5.1.6) lib/active_support/tagged_logging.rb:26:in tagged'
activesupport (5.1.6) lib/active_support/tagged_logging.rb:69:in tagged' railties (5.1.6) lib/rails/rack/logger.rb:24:in call'
sprockets-rails (3.2.1) lib/sprockets/rails/quiet_assets.rb:13:in call' actionpack (5.1.6) lib/action_dispatch/middleware/remote_ip.rb:79:in call'
actionpack (5.1.6) lib/action_dispatch/middleware/request_id.rb:25:in call' rack (2.0.6) lib/rack/method_override.rb:22:in call'
rack (2.0.6) lib/rack/runtime.rb:22:in call' activesupport (5.1.6) lib/active_support/cache/strategy/local_cache_middleware.rb:27:in call'
actionpack (5.1.6) lib/action_dispatch/middleware/executor.rb:12:in call' actionpack (5.1.6) lib/action_dispatch/middleware/static.rb:125:in call'
rack (2.0.6) lib/rack/sendfile.rb:111:in call' railties (5.1.6) lib/rails/engine.rb:522:in call'
puma (3.12.0) lib/puma/configuration.rb:225:in call' puma (3.12.0) lib/puma/server.rb:658:in handle_request'
puma (3.12.0) lib/puma/server.rb:472:in process_client' puma (3.12.0) lib/puma/server.rb:332:in block in run'
puma (3.12.0) lib/puma/thread_pool.rb:133:in `block in spawn_thread'

CLIENT
Started GET "/users/auth/doorkeeper/callback?code=ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc" for 127.0.0.1 at 2018-11-14 10:16:30 +0700
Processing by Users::OmniauthCallbacksController#failure as HTML
Parameters: {"code"=>"ba66e584f43faa8b36c3de4323ee5c60f5a0abe193aed6e8b12206d217091acc"}
Completed 500 Internal Server Error in 17ms

NameError (undefined local variable or method new_user_session_path' for #<Users::OmniauthCallbacksController:0x0055d5bd323258>): app/controllers/application_controller.rb:5:in new_session_path'

Rendered /home/nutrifood/.rvm/gems/ruby-2.1.0@doorkeeper-devise-client/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/_trace.erb (0.8ms)
Rendered /home/nutrifood/.rvm/gems/ruby-2.1.0@doorkeeper-devise-client/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/_request_and_response.erb (0.7ms)
Rendered /home/nutrifood/.rvm/gems/ruby-2.1.0@doorkeeper-devise-client/gems/actionpack-3.1.3/lib/action_dispatch/middleware/templates/rescues/diagnostics.erb within rescues/layout (13.7ms)

undefined method `new_session_path'

I'm gettting this error after signin in with oauth2 provider, in /users/auth/doorkeeper/callback:

undefined method `new_session_path' for #<Users::OmniauthCallbacksController:0x000000042d2978>

I've followed some tricks in heartcombo/devise#1390 with no success.

Any idea?

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.