Skip to content

Instantly share code, notes, and snippets.

@pfac
Created May 18, 2019 12:56
Show Gist options
  • Save pfac/95fc2b433ba3ca5931f0f8735ce5b714 to your computer and use it in GitHub Desktop.
Save pfac/95fc2b433ba3ca5931f0f8735ce5b714 to your computer and use it in GitHub Desktop.
Rails API authentication goodies
class Api::HelloController < Api::ApplicationController
include ActionController::HttpAuthentication::Token::ControllerMethods
def authenticate_user!
authenticate_or_request_with_http_token do |token|
# decode and/or verify token (!)
end
end
end
class PostsController < ApplicationController
# All actions fail with 401 UNAUTHORIZED if no token is provided
before_action :authenticate_user!
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment