Created
July 29, 2016 15:43
-
-
Save craigplummer/08fddd8ecb035526d0540b95e578e69c to your computer and use it in GitHub Desktop.
Using Microsoft Azure AD for API Authentication with Rails and Warden - azure_ad_json_web_token_strategy.rb
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
require 'azure_ad_json_web_token' | |
class AzureAdJsonWebTokenStrategy < ::Warden::Strategies::Base | |
def valid? | |
token | |
end | |
def authenticate! | |
if claims | |
success! claims | |
else | |
fail! | |
end | |
end | |
def claims | |
::AzureAdJsonWebToken.decode(token)[0] | |
rescue | |
nil | |
end | |
def token | |
unless request.env['HTTP_AUTHORIZATION'].nil? | |
request.env['HTTP_AUTHORIZATION'].split(' ').last | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment