Skip to content

Commit

Permalink
Fix persona bugs
Browse files Browse the repository at this point in the history
  • Loading branch information
VictorNicollet committed Mar 29, 2013
1 parent 795959b commit 8d8922d
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 7 deletions.
10 changes: 6 additions & 4 deletions ohmPersona/assets/script.coffee
Expand Up @@ -5,16 +5,18 @@
eval('(' + f[0] + ')').apply(@,f[1..])
navigator.id.watch
loggedInUser : current
onLogin : (assertion) ->
onlogin : (assertion) ->
$.ajax
url: login
contentType: 'application/json'
type: 'POST'
data: $.toJSON assertion
data: '"' + assertion.replace(/[\\"]/g,"\\$&") + '"'
success: success
onLogout : () ->
onlogout : () ->
$.ajax
url: logout
url: logout,
contentType: 'application/json'
data: "null"
type: 'POST'
success: success

Expand Down
26 changes: 23 additions & 3 deletions ohmPersona/ohmPersona.ml
Expand Up @@ -53,6 +53,8 @@ let init_full ?(cookie="PERSONA") ?(urlPrefix="persona/") ~server ~onLogin ~onLo
let! assertion = req_or (return res)
(Action.Convenience.get_json req |> BatOption.bind Fmt.String.of_json_safe) in

let () = Util.log "Assertion: %s" assertion in

let audience =
let domain = server # domain (req # server) in
let port = server # port (req # server) in
Expand All @@ -64,10 +66,28 @@ let init_full ?(cookie="PERSONA") ?(urlPrefix="persona/") ~server ~onLogin ~onLo
in

let! api = req_or (return res) begin
try let response = Http_client.Convenience.http_post validate
[ "audience", audience ; "assertion", assertion ] in
try let curl = Curl.init () in
let data = Json.serialize (Json.Object [
"audience", Json.String audience ;
"assertion", Json.String assertion
]) in
let response =
let buffer = Buffer.create 1763 in
Curl.set_url curl validate ;
Curl.set_writefunction curl (fun x -> Buffer.add_string buffer x ; String.length x) ;
Curl.set_post curl true ;
Curl.set_httpheader curl [
"Content-type: application/json";
] ;
Curl.set_postfields curl data ;
Curl.set_postfieldsize curl (String.length data) ;
Curl.perform curl ;
Curl.global_cleanup () ;
Buffer.contents buffer
in
let () = Util.log "Response : %s" response in
ApiResponse.of_json_string_safe response
with _ -> None
with exn -> Util.log "[FAIL] OhmPersona request : %s" (Printexc.to_string exn) ; None
end in

let! token, js = ohm (onLogin (req # server) (api # email)) in
Expand Down

0 comments on commit 8d8922d

Please sign in to comment.