doorkeeper | Doorkeeper is an OAuth 2 provider for Ruby on Rails / Grape | OAuth library
kandi X-RAY | doorkeeper Summary
kandi X-RAY | doorkeeper Summary
Doorkeeper is a gem (Rails engine) that makes it easy to introduce OAuth 2 provider functionality to your Ruby on Rails or Grape application.
Support
Quality
Security
License
Reuse
Top functions reviewed by kandi - BETA
- Validates the client access token .
- Redirect in the form of the auth response .
- POST
- Validate attributes .
- Updates an application
- Returns true if the secret matches the given secret
- Revoke an authorization request .
- Destroys the authorization mechanism .
- This method returns an array of authorization responses .
- Calculates the access rules for an access token
doorkeeper Key Features
doorkeeper Examples and Code Snippets
Community Discussions
Trending Discussions on doorkeeper
QUESTION
I have the following Android code
...ANSWER
Answered 2021-Dec-25 at 02:45I found it.
My curl command above is correct, however, it is not enough. Curl sends header content-type: application/x-www-form-urlencoded
by default. But since we are sending json data. We need to set it as content-type: application/json
.
So the working command is
QUESTION
According to The OAuth 2.0 Authorization Framework, when obtaining authorization via the Client Credentials Grant flow, it says: "The client credentials grant type MUST only be used by confidential clients."
I have implemented an OAuth 2.0 provider API with doorkeeper (Ruby on Rails gem). However, a non-confidential client application, created by the OAuth 2.0 provider, is able to use the Client Credentials Grant flow with its client_id only i.e. without client_secret. Is this an expected behaviour?
I came across this as I was looking to protect my Resource Server API, such that even for public endpoints that do not require an end-user to be autorized i.e. when the Client is the Resource Owner, the client is still required to provide an Access Token.
In this use case, the Authorization Code Grant flow is not relevant since the Resource Owner is not an end-user and as per the latest OAuth 2.0 security recommendations, the Implicit Grant flows is not advised. On this basis, I found that the Client Credentials Grant flow to be the most relevant flow but I want to double check if it's appropriate to use even though the OAuth 2.0 framework says that it MUST only be used by confidential clients.
...ANSWER
Answered 2021-Oct-23 at 20:07The client_credentials grant must only be used by confidential clients, because the client needs to store the secret. That is because the clients needs to send client_id and client_secret to the Authorization Server in order to get the Token. I don't know of any special way where the client_credentials flow can be used with only the client_id.
As far as I could see, the doorkeeper documentation also don't mention this.
But I wouldn't use client_credentials flow in a non confidential client, when the client needs to save the secret. And I would not use ANY Grant that only sends its client_id and nothing else to the /token endpoint to get a Token.
QUESTION
The Back Story
I am currently changing my Ruby on Rails app to a multi-database configuration. Main reason for the switch was to put my Member(User) and Profile tables in a separate database, which could be accessed from another RoR app; thus allowing me to have a single sign-on capability aside from using OAuth and Doorkeeper. This has been a many many hours project with many crazy hurdles. Finally tonight it seemed that everything was working, until I ran my spec tests, and one of my work arounds I did today is throwing flags.
Here is the appropriate code for the problem, simplified for brevity sake.
Any help would be greatly appreciated. Thank you.
Models
app/models/members_record.rb
...ANSWER
Answered 2021-Jul-16 at 10:03This is supported natively on Rails 7 upwards. (See https://edgeguides.rubyonrails.org/active_record_multiple_databases.html#handling-associations-with-joins-across-databases, https://github.blog/2021-07-12-adding-support-cross-cluster-associations-rails-7/ and https://github.com/rails/rails/pull/41937)
If you really need this, I'd probably recommend moving to rails master, and use the native way:
QUESTION
I have a Rails 6.1 app using devise 4.7.1, doorkeeper 5.5.1, and devise-doorkeeper 1.2.0.
I'm trying to run through a (PKCE) OAuth flow, but the final step -- a POST request to /oauth/token
-- returns a 401 Unauthorized error with the JSON content {"error": "You need to sign in or sign up before continuing."}
.
I'm confused about this, since the /oauth/token
endpoint should be accessible to unauthenticated users as far as I understand. What's also weird (but perhaps a red herring) is that if I attempt to run the same POST request with curl, but remove the User-Agent header, it succeeds.
My current suspect is this block of code in initializers/doorkeeper.rb
:
ANSWER
Answered 2021-May-05 at 19:47This problem was caused by our use of the Ahoy analytics library.
By default, this library tracks all page visits in your Rails app. It tries to get the current user using current_user || current_resource_owner
. Because current_user
was still nil when POSTing to /oauth/token
, getting current_resource_owner
ended up calling our Doorkeeper resource_owner_authenticator
, which returned the 401 error. The source code for this is here.
This also explains why things worked as expected when unsetting the User-Agent
header: with no user agent (or the user agent of e.g. curl), Ahoy treats the request as coming from a bot, and doesn't attempt to track it (source code here).
Our solution to this is to tell Ahoy to stop tracking all page views automatically by setting Ahoy.api_only = true
in its configuration.
QUESTION
We have an oauth server that uses doorkeeper. We want to start using doorkeeper jwt, but we can't turn it on for all oauth clients yet as some are out of our control and we are pretty sure they are storing the access tokens their apps receive in a varchar(255) column which won't work if we start to hand out JWT tokens for all apps. Also we don't really want to be storing the whole JWT in our database either if we can avoid it.
Our idea is to have doorkeeper generate an opaque access token for all apps first, and store that in the db. Then before return the opaque access token to the app, we check to see if the app has JWT tokens turned on and if so convert the opaque access token to a JWT access token using the opaque access token as the JWT's jti
claim. We are thinking of utilizing the before_successful_strategy_response
callback to convert to a JWT using the doorkeeper-jwt gem if the app has JWT access tokens enabled.
Then, when we get a request which has an access token, check to see if the access token is a JWT access token, and if so read the jti
claim out of it and use that to load the access token from the db. We don't have a good place to hook into this at the moment. Right now we are thinking of monkey patching Doorkeeper::Oauth::Token in the from_request
method to check to see if the token is a JWT before returning it, and if so, return the JWTs jti
instead.
Does that seem like a reasonable approach? Is there another way without monkey patching Doorkeeper::Oauth::Token?
...ANSWER
Answered 2021-Feb-05 at 18:25More recent versions of doorkeeper allow you to configure the access token model class as seen here: https://github.com/doorkeeper-gem/doorkeeper/blob/55488ccd9910e0c45ed4342617da8e026f4f55b5/lib/doorkeeper/oauth/token.rb#L17
So we can hook into the access token lookup there without resorting to monkey patching.
QUESTION
I am building 2 apps; a front-end, and a back-end.
The back-end will be built using Rails API + Doorkeeper Gem (oauth2 provider) while the front-end will be built using React Native.
Currently, I am using "Client Credentials Grant Flow" which works just fine at the moment. But after researching for a while, this flow shouldn't be used in a client-only app as it exposes the client_secret
if ever someone decompiles the app.
I have also read about "Implicit Grant Flow" which only requires client_id
. But this flow seems old now?
And according to this: https://auth0.com/docs/api-auth/which-oauth-flow-to-use#is-the-client-a-single-page-app-
It is recommending to use "Authorization Code Grant with PKCE" over "Implicit Grant Flow". I am able to make it work but the problem is that it still needs the client_secret
in order to get an access_token
, is this how it should be?
Here is the sample flow I am doing:
...ANSWER
Answered 2020-Jul-23 at 17:12- Do we really need client_secret to get access_token on PKCE flow?
It depends. Originally PKCE was introduced to protect public clients (a client which cannot protect a secret). But in recent best practices, PKCE became kind of a recommendation for authorization code grant (source)
2.1.1. Authorization Code Grant
Clients MUST prevent injection (replay) of authorization codes into
the authorization response by attackers. The use of PKCE [RFC7636]
is RECOMMENDED to this end. The OpenID Connect "nonce" parameter and ID Token Claim [OpenID] MAY be used as well. The PKCE challenge or
OpenID Connect "nonce" MUST be transaction-specific and securely
bound to the client and the user agent in which the transaction was
started.Note: although PKCE so far was designed as a mechanism to protect
native apps, this advice applies to all kinds of OAuth clients,
including web applications.
- Why is it recommended to use "PKCE Flow" if it will just expose the client_secret?
In short, to avoid authorization code replay attacks (spec - introduction). And this happens inside end user's device and not in the transmission of data. TLS is mandatory for OAuth 2.0 token request.
- How is it different from "Client Credentials Grant Flow" which also exposes the client_secret?
No grant will expose credentials as token requests are done via TLS.
I think in your case, the client is a confidential client (spec - client types). So I would recommend to check this aspect in authorization server.
QUESTION
When i try to use the sign_up method of Devise, i get an internal server error but, after create the user.
My application.rb:
...ANSWER
Answered 2020-Apr-30 at 22:40This issue seems to be the problem you are having:
https://github.com/heartcombo/devise/issues/4603
They suggest clearing the cookies of your browser
this usually happens when you are upgrading a bunch of stuck including devise in one branch And than you get back to some other branch for something and you have this newer cookie in your browser. Simple solution is to clear cookies in browser.
Other answers mention upgrading devise version
QUESTION
I'm trying to test CredentialsController
, which works fine in production, using RSpec request specs.
ANSWER
Answered 2020-Mar-19 at 20:36I was passing the token wrong. Instead of:
QUESTION
I'm writing an RSpec request spec, which looks roughly like (somewhat shortened for brevity):
...ANSWER
Answered 2020-Mar-19 at 07:18have you thought not to mock current_user
at all?
if you write a test helper to sign in a user
before your request spec, current_user
will be populate automatically as if it was a real user. The code would look like this:
QUESTION
In the upgrade docs there's a note about the default response status moving from 401 to 400 (https://github.com/doorkeeper-gem/doorkeeper/wiki/Migration-from-old-versions#api-changes-2).
This is going to break my clients until we can get them to upgrade (/handle both cases in the short term).
How can I reinstate the 401 response until such a time as my clients can update?
Thanks!
...ANSWER
Answered 2020-Feb-07 at 22:21You can check the changes made in https://github.com/doorkeeper-gem/doorkeeper/pull/1202/files and try to patch Doorkeeper::OAuth::ErrorResponse
to return status you need. Then when you would be ready to migrate - just remove the patch. All you need is to overrida status
method. Also check InvalidTokenResponse
class, maybe you need to patch it too.
There is no built-in option to switch status code in DOorkeeper so you can only patch its' internals.
Community Discussions, Code Snippets contain sources that include Stack Exchange Network
Vulnerabilities
No vulnerabilities reported
Install doorkeeper
Support
Reuse Trending Solutions
Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items
Find more librariesStay Updated
Subscribe to our newsletter for trending solutions and developer bootcamps
Share this Page