A library for providing BankID services as an RP (Relying party). Supports the latest v5 features.
Check out the API Documentation http://godoc.org/github.com/NicklasWallgren/bankid
The library can be installed through go get
go get github.com/stimtech/go-bankid
We support the two major Go versions, which are 1.17 and 1.18 at the moment.
- Supports all v5.1 features
// Creates new BankID instance
New(configuration *configuration.Configuration) (*BankID)
// Initiates an authentication order
(b BankID) Authenticate(context context.Context, payload *AuthenticationPayload) (*AuthenticateResponse, error)
// Initiates an sign order
(b BankID) Sign(context context.Context, payload *SignPayload) (*SignResponse, error)
// Collects the result of a sign or auth order suing the orderRef as reference
(b BankID) Collect(context context.Context, payload *CollectPayload) (*CollectResponse, error)
// Cancels an ongoing sign or auth order
(b BankID) Cancel(context context.Context, payload *CancelPayload) (*CancelResponse, error)
import (
"context"
"fmt"
"io/ioutil"
"github.com/NicklasWallgren/bankid"
"github.com/NicklasWallgren/bankid/configuration"
)
certificate, err := ioutil.ReadFile("path/to/environment.p12")
if err != nil {
panic(err)
}
config := configuration.New(
configuration.TestEnvironment,
&configuration.Pkcs12{Content: certificate, Password: "p12 password"},
)
bankId := bankid.New(config)
payload := bankid.SignPayload{PersonalNumber: "<INSERT PERSONAL NUMBER>", EndUserIP: "192.168.1.1", UserVisibleData: "Test"}
response, err := bankId.Sign(context.Background(), &payload)
if err != nil {
if response, ok := err.(*bankid.ErrorResponse); ok {
fmt.Printf("ErrResponse: %s - %s \n", response.Details, response.ErrorCode)
}
fmt.Printf("%#v", err)
return
}
fmt.Println(response.Collect(ctx))
go test -v -race $(go list ./... | grep -v vendor)
We use GitHub Actions to make sure the codebase is consistent (golangci-lint run
) and continuously tested (go test -v -race $(go list ./... | grep -v vendor)
). We try to keep comments at a maximum of 120 characters of length and code at 120.
If you find any problems or have suggestions about this library, please submit an issue. Moreover, any pull request, code review and feedback are welcome.