From 627a217e7e74a6800475a9b3898855b26edd4a16 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Thu, 20 Sep 2012 02:50:07 +0200 Subject: pseudo persona stuff --- auth_persona.go | 69 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 69 insertions(+) create mode 100644 auth_persona.go (limited to 'auth_persona.go') diff --git a/auth_persona.go b/auth_persona.go new file mode 100644 index 0000000..7895c2d --- /dev/null +++ b/auth_persona.go @@ -0,0 +1,69 @@ +package main + +import ( + "encoding/json" + "io" + "io/ioutil" + "log" + "net/http" + "net/url" +) + +type PersonaResponse struct { + Status, Email, Reason string +} + +func (b PersonaResponse) Okay() bool { + return b.Status == "okay" +} + +func VerifyPersonaAssertion(assertion, audience string) PersonaResponse { + resp, _ := http.PostForm( + "https://browserid.org/verify", + url.Values{ + "assertion": {assertion}, + "audience": {audience}, + }) + response := personaResponseFromJson(resp.Body) + resp.Body.Close() + + return response +} + +func personaResponseFromJson(r io.Reader) (resp PersonaResponse) { + body, err := ioutil.ReadAll(r) + + if err != nil { + log.Fatal(err) + } + + err = json.Unmarshal(body, &resp) + + if err != nil { + log.Fatal(err) + } + + return resp +} + +type PersonaAuth bool + +func (pa PersonaAuth) CheckLogin(name, pw string) error { + return nil +} + +func (pa PersonaAuth) NewAccount(name, pw, email string) error { + return nil +} + +func (pa PersonaAuth) ChangePassword(name, oldPw, newPw string) error { + return nil +} + +func (pa PersonaAuth) GetEmail(name string) (string, error) { + return "example@localhost", nil +} + +func (pa PersonaAuth) GetUserName(name string) (string, error) { + return "common", nil +} -- cgit v1.2.3