Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save craigplummer/08fddd8ecb035526d0540b95e578e69c to your computer and use it in GitHub Desktop.
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
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