Created
March 16, 2012 04:59
-
-
Save RichardJordan/2048567 to your computer and use it in GitHub Desktop.
browserid auth with rails
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
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