This file contains hidden or 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
| Rails.application.routes.draw do | |
| get :index, to: 'home#index' | |
| end |
This file contains hidden or 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
| class HomeController < ApplicationController | |
| before_action :authenticate_user | |
| def index | |
| render json: current_user || 'The user isn\'t authenticated'. | |
| end | |
| end |
This file contains hidden or 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
| class ApplicationController < ActionController::API | |
| include Knock::Authenticable | |
| end |
This file contains hidden or 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
| ... | |
| # Find our User by id in test environment, and auth0_uid in other environments. | |
| Knock::AuthToken.class_eval do | |
| def entity_for(entity_class) | |
| key_to_find = Rails.env.test? ? :id : :auth0_uid | |
| entity_class.find_by(key_to_find => @payload['sub']) | |
| end | |
| end |
This file contains hidden or 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
| module Auth0 | |
| class Signin | |
| def self.perform(email, password) | |
| ctx = OpenSSL::SSL::SSLContext.new | |
| ctx.verify_mode = OpenSSL::SSL::VERIFY_NONE | |
| HTTP.headers(accept: 'application/json') | |
| .post( | |
| "https://#{ENV['AUTH0_DOMAIN']}/oauth/token", | |
| ssl_context: ctx, |
This file contains hidden or 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
| module Auth0 | |
| class Signup | |
| def self.perform(email, password) | |
| HTTP.headers(accept: 'application/json') | |
| .post( | |
| "https://#{ENV['AUTH0_DOMAIN']}/dbconnections/signup", | |
| form: { | |
| client_id: ENV['AUTH0_CLIENT_ID'], | |
| email: email, | |
| password: password, |
This file contains hidden or 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
| Knock.setup do |config| | |
| if Rails.env.test? | |
| config.token_secret_signature_key = -> { Rails.application.credentials.read } | |
| else | |
| config.token_audience = -> { ENV['AUTH0_AUDIENCE'] } | |
| # Auth0 uses RS256. | |
| config.token_signature_algorithm = 'RS256' | |
| # API secret from Auth0. |
This file contains hidden or 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
| ... | |
| # Handle JWT with auth0 | |
| gem 'knock', '~> 2.0' | |
| # To perform http requests. | |
| gem 'http' | |
| ... |
This file contains hidden or 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
| ... | |
| group :development do | |
| gem 'listen', '>= 3.0.5', '< 3.2' | |
| # Spring speeds up development by keeping your application running in the background. Read more: https://github.com/rails/spring | |
| gem 'spring' | |
| gem 'spring-watcher-listen', '~> 2.0.0' | |
| # Manage env variables. | |
| gem 'dotenv-rails' | |
| end |
This file contains hidden or 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
| class User < ApplicationRecord | |
| validates_presence_of :auth0_uid, :email | |
| end |