Skip to content

Instantly share code, notes, and snippets.

@RichardJordan
Created March 16, 2012 04:59
Show Gist options
  • Save RichardJordan/2048567 to your computer and use it in GitHub Desktop.
Save RichardJordan/2048567 to your computer and use it in GitHub Desktop.
browserid auth with rails
def signIn #with browserid
ans = 'invalid'
if (params['BIDASSERT'] != nil)
assertion = params['BIDASSERT']
audience = request.host_with_port
http = Net::HTTP.new('browserid.org', 443)
http.use_ssl = true
headers = {
'Content-Type' => 'application/x-www-form-urlencoded',
}
data = "audience="+audience+"&assertion="+assertion
resp, data = http.post("/verify",data,headers)
begin
bid_resp = JSON.parse(data)
if (bid_resp['status'] == "okay")
if author = Author.find_by_email(bid_resp['email'])
session[:user_id] = author.id
ans = "logged in"
end
end
rescue JSON::ParserError
logger.info "BrowserId returning bad JSON?"
end
end
render :text => ans
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment