aboutsummaryrefslogtreecommitdiffstats
path: root/auth_persona.go
blob: 7895c2de8a9ad05f0a865b2b236a3ab2ccee5510 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
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
}