-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathauthenticate.go
60 lines (51 loc) · 1.69 KB
/
authenticate.go
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
package bankid
import (
"encoding/xml"
"errors"
"fmt"
"log"
)
type authenticateRequest struct {
XMLName xml.Name `xml:"typ:AuthenticateRequest"`
//<!--Optional:-->
Ssn string `xml:"personalNumber"`
//<!--0 to 20 repetitions:-->
UserInfo *EndUserInfo `xml:",omitempty"`
//<!--Optional:-->
Alternatives []interface{} `xml:",omitempty"`
}
// EndUserInfo is information about the enduser that will be sent to bankid-api
type EndUserInfo struct {
XMLName xml.Name `xml:"endUserInfo"`
UserInfoType string `xml:"type"`
Value string `xml:"value"`
}
// AuthResponse is the response from a bankid auth-request
type AuthResponse struct {
XMLName xml.Name `xml:"AuthResponse"`
OrderRef string `xml:"orderRef"`
AutoStartToken string `xml:"autoStartToken"`
}
// Authenticate is a method to call the Authenticate resource on the BankID API.
func (c *Client) Authenticate(ssn string, u *EndUserInfo) (*AuthResponse, error) {
respEnvelope := new(soapEnvelope)
respEnvelope.Body = soapBody{Content: &AuthResponse{}}
a := &authenticateRequest{
Ssn: ssn,
UserInfo: u,
}
err := c.RoundTripSoap12("Authenticate", a, respEnvelope)
if err != nil {
return nil, err
}
if respEnvelope.Body.Fault != nil {
err := fmt.Errorf("errorcode: %v \n string: %v \n faultStatus: %v \n detailed: %v", respEnvelope.Body.Fault.String, respEnvelope.Body.Fault.Code, respEnvelope.Body.Fault.Detail.FaultStatus, respEnvelope.Body.Fault.Detail.Description)
return nil, err
}
resp, ok := respEnvelope.Body.Content.(*AuthResponse)
if !ok {
return nil, errors.New("authResp not ok")
}
log.Printf("AutostartToken: %v\n OrderRef: %v\n", resp.AutoStartToken, resp.OrderRef)
return resp, nil
}