-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Add Auth0 support for users signup and signin
- Loading branch information
1 parent
1a412f1
commit 873bf70
Showing
15 changed files
with
320 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# Auth0 integration | ||
|
||
## How to create an application | ||
|
||
When you signed up for Auth0, a new application was created for you, or you could have created a new one (the most appropriate application for our structure is Single Page Application). | ||
 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
You will need some details about that application to communicate with Auth0. You can get these details from the Application Settings section in the Auth0 dashboard. | ||
|
||
 | ||
This comment has been minimized.
Sorry, something went wrong. |
||
|
||
You should put `auth0_domain` from the Domain field and `auth0_client_id` from the Client ID field | ||
|
||
For a single page application better to use authorization code flow with proof key for code exchange. | ||
|
||
## Authorization Code Flow with Proof Key for Code Exchange (PKCE) | ||
When public clients request Access Tokens, some additional security concerns are posed that are not mitigated by the Authorization Code Flow alone. This is because single-page apps cannot securely store a Client Secret because their entire source is available to the browser. | ||
|
||
|
||
### How it works | ||
 | ||
Because the PKCE-enhanced Authorization Code Flow builds upon the standard Authorization Code Flow, the steps are very similar. | ||
|
||
1. The user clicks Login within the application. | ||
|
||
2. Auth0's SDK creates a cryptographically-random code_verifier and from this generates a code_challenge. | ||
|
||
3. Auth0's SDK redirects the user to the Auth0 Authorization Server (/authorize endpoint) along with the code_challenge. | ||
|
||
4. Your Auth0 Authorization Server redirects the user to the login and authorization prompt. | ||
|
||
5. The user authenticates using one of the configured login options and may see a consent page listing the permissions Auth0 will give to the application. | ||
|
||
6. Your Auth0 Authorization Server stores the code_challenge and redirects the user back to the application with an authorization code, which is good for one use. | ||
|
||
7. Auth0's SDK sends this code and the code_verifier (created in step 2) to the Auth0 Authorization Server (/oauth/token endpoint). | ||
|
||
8. Your Auth0 Authorization Server verifies the code_challenge and code_verifier. | ||
|
||
9. Your Auth0 Authorization Server responds with an ID Token and Access Token (and optionally, a Refresh Token). | ||
|
||
10. Your application can use the Access Token to call an API to access information about the user. | ||
|
||
11. The API responds with requested data. | ||
|
||
You can try to call your [API using the authorization Code Flow with PKCE](https://auth0.com/docs/flows/call-your-api-using-the-authorization-code-flow-with-pkce). | ||
|
||
Also you can find a link with [Authentication API description](https://auth0.com/docs/api/authentication#introduction) here. |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
# frozen_string_literal: true | ||
|
||
module Barong | ||
module Auth0 | ||
class JWT | ||
def self.verify(token) | ||
::JWT.decode(token, | ||
nil, | ||
true, # Verify the signature of this token | ||
algorithms: 'RS256', | ||
iss: "https://#{Barong::App.config.auth0_domain}/", | ||
verify_iss: true, | ||
aud: Barong::App.config.auth0_client_id, | ||
verify_aud: true | ||
) do |header| | ||
jwks_hash[header['kid']] | ||
end | ||
end | ||
|
||
def self.jwks_hash | ||
uri = "https://#{Barong::App.config.auth0_domain}/.well-known/jwks.json" | ||
jwks_raw = Net::HTTP.get URI(uri) | ||
jwks_keys = Array(JSON.parse(jwks_raw)['keys']) | ||
Hash[jwks_keys.map do |k| | ||
[ | ||
k['kid'], | ||
OpenSSL::X509::Certificate.new(Base64.decode64(k['x5c'].first)).public_key | ||
] | ||
end | ||
] | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Hi! @chumaknadya @calj
Good job!
Pay your attention. It is bad practice to identify user by its email. Email could be changed. Use
sub
key of JWT instead.Best flow is:
sub
. If it is found use them and return session.sub
. Update itssub
and return session.email
andsub
. Process situation where user with such email already exists.BTW Why don't your make standard oauth2 authorisation callbacks? auth2 support it too.
👍