Skip to content

Instantly share code, notes, and snippets.

@StabbyMcDuck
Last active November 20, 2016 14:29
Show Gist options
  • Save StabbyMcDuck/edfb8cb8e27599e3729ea63059394c70 to your computer and use it in GitHub Desktop.
Save StabbyMcDuck/edfb8cb8e27599e3729ea63059394c70 to your computer and use it in GitHub Desktop.
module OmniAuth
module Strategies
class YOUR_APP_HttpBasic
include OmniAuth::Strategy
option :callback_path, "/auth/YOUR-APP-http-basic/callback"
credentials {
{
token: identity.oauth_token
}
}
info {
{
name: identity.user.name
}
}
uid {
identity.uid
}
def callback_phase
return fail!(:invalid_credentials) unless identity
super
end
private
def identity
@identity ||= ActionController::HttpAuthentication::Basic.authenticate(
ActionDispatch::Request.new(request.env)
) { |user, password|
Identity.find_by(oauth_token: password, provider: 'YOUR_APP_http_basic', uid: user)
}
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment