Skip to content

Commit

Permalink
#30 - Move to a new module path
Browse files Browse the repository at this point in the history
  • Loading branch information
NicklasWallgren committed Feb 17, 2024
1 parent f9774e1 commit 5744ba6
Show file tree
Hide file tree
Showing 19 changed files with 72 additions and 73 deletions.
2 changes: 1 addition & 1 deletion .golangci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ linters-settings:
gci:
sections:
- standard
- prefix(github.com/NicklasWallgren/bankid)
- prefix(github.com/e-identification/bankid)
- default
custom-order: true

Expand Down
21 changes: 7 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
# BankID library

[![Build Status](https://github.com/NicklasWallgren/bankid/workflows/Test/badge.svg)](https://github.com/NicklasWallgren/bankid/actions?query=workflow%3ATest)
[![Reviewdog](https://github.com/NicklasWallgren/bankid/workflows/reviewdog/badge.svg)](https://github.com/NicklasWallgren/bankid/actions?query=workflow%3Areviewdog)
[![Go Report Card](https://goreportcard.com/badge/github.com/NicklasWallgren/bankid)](https://goreportcard.com/report/github.com/NicklasWallgren/bankid)
[![GoDoc](https://godoc.org/github.com/NicklasWallgren/bankid?status.svg)](https://godoc.org/github.com/NicklasWallgren/bankid)
[![Build Status](https://github.com/e-identification/bankid/workflows/Test/badge.svg)](https://github.com/e-identification/bankid/actions?query=workflow%3ATest)
[![Reviewdog](https://github.com/e-identification/bankid/workflows/reviewdog/badge.svg)](https://github.com/e-identification/bankid/actions?query=workflow%3Areviewdog)
[![Go Report Card](https://goreportcard.com/badge/github.com/e-identification/bankid)](https://goreportcard.com/report/github.com/e-identification/bankid)
[![GoDoc](https://godoc.org/github.com/e-identification/bankid?status.svg)](https://godoc.org/github.com/e-identification/bankid)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/cabd5fbbcde543ec959fb4a3581600ed)](https://app.codacy.com/gh/NicklasWallgren/bankid?utm_source=github.com&utm_medium=referral&utm_content=NicklasWallgren/bankid&utm_campaign=Badge_Grade)

A library for providing BankID services as an RP (Relying party).
Supports the latest v6 features.

To learn how to use the library, please refer to the [documentation](https://godoc.org/github.com/NicklasWallgren/bankid/v2). There are some [examples](./examples) that may be useful as well.
To learn how to use the library, please refer to the [documentation](https://godoc.org/github.com/e-identification/bankid). There are some [examples](./examples) that may be useful as well.

# Installation
The library can be installed through `go get`
```bash
go get github.com/NicklasWallgren/bankid/v2
go get github.com/e-identification/bankid
```

# Supported versions
Expand Down Expand Up @@ -49,24 +49,17 @@ NewBankIDClient(configuration *configuration.Configuration) (*BankIDClient)

## Unit tests
```bash
go test -v -race $(go list ./... | grep -v vendor)
go test -v -race $(go list ./...)
```

### Code Guide

We use GitHub Actions to make sure the codebase is consistent (`golangci-lint run`) and continuously tested (`go test -v -race $(go list ./...)`). We try to keep comments at a maximum of 120 characters of length and code at 120.


## Contributing

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.

## Contributors
- [Nicklas Wallgren](https://github.com/NicklasWallgren)
- [All Contributors][link-contributors]

[link-contributors]: ../../contributors

## License

[MIT](./LICENSE)
17 changes: 10 additions & 7 deletions examples/authenticate.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,22 +8,25 @@ import (
"path"
"runtime"

"github.com/NicklasWallgren/bankid/v2/pkg"
"github.com/NicklasWallgren/bankid/v2/pkg/configuration"
"github.com/NicklasWallgren/bankid/v2/pkg/payload"
"github.com/e-identification/bankid/pkg"
"github.com/e-identification/bankid/pkg/configuration"
"github.com/e-identification/bankid/pkg/payload"
)

func main() {
configuration := configuration.NewConfiguration(
clientConfiguration := configuration.NewConfiguration(
configuration.TestEnvironment,
&configuration.Pkcs12{Content: loadPkcs12(getResourcePath("certificates/test.p12")), Password: "qwerty123"},
)

bankID, err := pkg.NewBankIDClient(configuration)
bankID, err := pkg.NewBankIDClient(clientConfiguration)

payload := payload.AuthenticationPayload{EndUserIP: "192.168.1.1", UserVisibleData: "blabla", Requirement: &payload.Requirement{PersonalNumber: "201912312392"}}
authenticationPayload := payload.AuthenticationPayload{
EndUserIP: "192.168.1.1", UserVisibleData: "To be showed in the BankID application ",
Requirement: &payload.Requirement{PersonalNumber: "201912312392"},
}

httpResponse, err := bankID.Authenticate(context.Background(), &payload)
httpResponse, err := bankID.Authenticate(context.Background(), &authenticationPayload)
if err != nil {
var apiError *pkg.APIError

Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module github.com/NicklasWallgren/bankid/v2
module github.com/e-identification/bankid

go 1.21

Expand Down
13 changes: 7 additions & 6 deletions pkg/bankid.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (
"errors"
"fmt"

"github.com/NicklasWallgren/bankid/v2/pkg/configuration"
"github.com/NicklasWallgren/bankid/v2/pkg/internal"
"github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
"github.com/NicklasWallgren/bankid/v2/pkg/payload"
"github.com/NicklasWallgren/bankid/v2/pkg/response"
"github.com/e-identification/bankid/pkg/configuration"
"github.com/e-identification/bankid/pkg/internal"
"github.com/e-identification/bankid/pkg/internal/http"
"github.com/e-identification/bankid/pkg/payload"
"github.com/e-identification/bankid/pkg/response"

playground "gopkg.in/go-playground/validator.v9"
)
Expand Down Expand Up @@ -71,7 +71,8 @@ type QRCodeContentGenerator interface {
// QRCodeContent - Generates the QR code content based on qrStartToken, qrStartSecret and seconds elapsed since
// response.
//
// The QR code is generated by the RP every second using the pattern "bankid.qrStartToken.time.qrAuthCode" as input.
// The QR code is generated by the RP every second using the pattern "bankid.qrStartToken.time.qrAuthCode"
// as input.
QRCodeContent(qrStartToken, qrStartSecret string, seconds int) (string, error)
}

Expand Down
44 changes: 23 additions & 21 deletions pkg/bankid_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ import (
"runtime"
"testing"

"github.com/NicklasWallgren/bankid/v2/pkg/configuration"
bankIdHttp "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
"github.com/NicklasWallgren/bankid/v2/pkg/payload"
"github.com/e-identification/bankid/pkg/configuration"
bankIdHttp "github.com/e-identification/bankid/pkg/internal/http"
"github.com/e-identification/bankid/pkg/payload"

"github.com/stretchr/testify/assert"
"gopkg.in/go-playground/validator.v9"
Expand All @@ -26,11 +26,11 @@ func TestAuthenticate(t *testing.T) {
bankID, teardown := testBankID(fileToResponseHandler(t, "resource/test_data/sign_response.json"))
defer teardown()

payload := &payload.AuthenticationPayload{
requestPayload := &payload.AuthenticationPayload{
EndUserIP: "192.168.1.1", Requirement: &payload.Requirement{PersonalNumber: "123456789123"},
}

response, err := bankID.Authenticate(context.Background(), payload)
response, err := bankID.Authenticate(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand All @@ -44,11 +44,11 @@ func TestPhoneAuthentication(t *testing.T) {
bankID, teardown := testBankID(fileToResponseHandler(t, "resource/test_data/phone_sign_response.json"))
defer teardown()

payload := &payload.PhoneAuthenticationPayload{
requestPayload := &payload.PhoneAuthenticationPayload{
PersonalNumber: "123456789123", CallInitiator: "RP", UserVisibleData: "Test",
}

response, err := bankID.PhoneAuthenticate(context.Background(), payload)
response, err := bankID.PhoneAuthenticate(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand All @@ -66,13 +66,13 @@ func TestSign(t *testing.T) {
bankID, teardown := testBankID(fileToResponseHandler(t, "resource/test_data/sign_response.json"))
defer teardown()

payload := &payload.SignPayload{
requestPayload := &payload.SignPayload{
EndUserIP: "192.168.1.1",
UserVisibleData: "Test",
Requirement: &payload.Requirement{CardReader: "", PersonalNumber: "123456789123"},
}

response, err := bankID.Sign(context.Background(), payload)
response, err := bankID.Sign(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand All @@ -90,9 +90,11 @@ func TestPhoneSign(t *testing.T) {
bankID, teardown := testBankID(fileToResponseHandler(t, "resource/test_data/phone_sign_response.json"))
defer teardown()

payload := &payload.PhoneSignPayload{PersonalNumber: "123456789123", CallInitiator: "RP", UserVisibleData: "Test"}
requestPayload := &payload.PhoneSignPayload{
PersonalNumber: "123456789123", CallInitiator: "RP", UserVisibleData: "Test",
}

response, err := bankID.PhoneSign(context.Background(), payload)
response, err := bankID.PhoneSign(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand All @@ -110,12 +112,12 @@ func TestSignWithInvalidPayload(t *testing.T) {
bankID, _ := NewBankIDClient(configuration.NewConfiguration(configuration.TestEnvironment,
&configuration.Pkcs12{Content: loadFile(getResourcePath("certificates/test.p12")), Password: "qwerty123"}))

payload := &payload.SignPayload{
requestPayload := &payload.SignPayload{
EndUserIP: "192.168.1.1",
UserVisibleData: "Test",
Requirement: &payload.Requirement{CardReader: "", PersonalNumber: "INVALID-PERSONAL-NUMBER"},
}
_, err := bankID.Sign(context.Background(), payload)
_, err := bankID.Sign(context.Background(), requestPayload)

var validationErrors validator.ValidationErrors

Expand All @@ -132,9 +134,9 @@ func TestCollect(t *testing.T) {
bankID, teardown := testBankID(fileToResponseHandler(t, "resource/test_data/collect_response.json"))
defer teardown()

payload := &payload.CollectPayload{OrderRef: ""}
requestPayload := &payload.CollectPayload{OrderRef: ""}

response, err := bankID.Collect(context.Background(), payload)
response, err := bankID.Collect(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand All @@ -148,9 +150,9 @@ func TestCancel(t *testing.T) {
bankID, teardown := testBankID(stringToResponseHandler(t, "{}"))
defer teardown()

payload := &payload.CancelPayload{OrderRef: ""}
requestPayload := &payload.CancelPayload{OrderRef: ""}

response, err := bankID.Cancel(context.Background(), payload)
response, err := bankID.Cancel(context.Background(), requestPayload)
if err != nil {
t.Fatal(err)
}
Expand Down Expand Up @@ -178,14 +180,14 @@ func TestQRCodeContent(t *testing.T) {
// Returns a bankID whose requests will always return
// a response configured by the handler.
func testBankID(handler http.HandlerFunc) (*BankIDClient, func()) {
configuration := configuration.NewConfiguration(configuration.TestEnvironment,
clientConfiguration := configuration.NewConfiguration(configuration.TestEnvironment,
&configuration.Pkcs12{Content: loadFile(getResourcePath("certificates/test.p12")), Password: "qwerty123"})

bankID, _ := NewBankIDClient(configuration)
bankID, _ := NewBankIDClient(clientConfiguration)

httpClient, teardown := testHTTPClient(handler)

client, _ := bankIdHttp.NewClient(configuration, bankIdHttp.WithHTTPClient(httpClient))
client, _ := bankIdHttp.NewClient(clientConfiguration, bankIdHttp.WithHTTPClient(httpClient))
bankID.client = client

return bankID, teardown
Expand All @@ -201,7 +203,7 @@ func testHTTPClient(handler http.Handler) (*http.Client, func()) {
},
// #nosec G402
TLSClientConfig: &tls.Config{
InsecureSkipVerify: true,
InsecureSkipVerify: true, // nolint:gosec
},
},
}
Expand Down
4 changes: 2 additions & 2 deletions pkg/internal/http/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"net/http"
"strings"

"github.com/NicklasWallgren/bankid/v2/pkg/configuration"
"github.com/e-identification/bankid/pkg/configuration"
)

// The known API endpoints status codes.
Expand Down Expand Up @@ -84,7 +84,7 @@ func (c client) Call(ctx context.Context, request *Request) (Response, error) {
return c.decoder.decode(request, resp) // nolint:wrapcheck
}

// newRequest creates and prepares a instance of http Request.
// newRequest creates and prepares an instance of http Request.
func (c client) newRequest(context context.Context, url string, body io.Reader) (*http.Request, error) {
req, err := http.NewRequestWithContext(context, http.MethodPost, url, body)
req.Header.Add("Content-Type", "application/json")
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/http/decode.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"fmt"
"net/http"

"github.com/NicklasWallgren/bankid/v2/pkg/internal"
"github.com/e-identification/bankid/pkg/internal"
)

type statusCodeRange struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/http/decode_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"strings"
"testing"

"github.com/NicklasWallgren/bankid/v2/pkg/response"
"github.com/e-identification/bankid/pkg/response"
)

func TestDecodeUsingInvalidHttpResponse(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion pkg/internal/http/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (
"encoding/base64"
"fmt"

"github.com/NicklasWallgren/bankid/v2/pkg/configuration"
"github.com/e-identification/bankid/pkg/configuration"

"software.sslmate.com/src/go-pkcs12"
)
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/authentication.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// AuthenticationPayload holds the required and optional fields of the authentication request.
type AuthenticationPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/cancel.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// CancelPayload holds the required fields of the collect Payload.
type CancelPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/collect.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// CollectPayload holds the required fields of the collect Payload.
type CollectPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/phoneauthentication.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// PhoneAuthenticationPayload holds the required and optional fields of the phone authentication request.
type PhoneAuthenticationPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/phonesign.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// PhoneSignPayload holds the required and optional fields for the phone sign payload.
type PhoneSignPayload struct {
Expand Down
2 changes: 1 addition & 1 deletion pkg/payload/sign.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package payload

import "github.com/NicklasWallgren/bankid/v2/pkg/internal/http"
import "github.com/e-identification/bankid/pkg/internal/http"

// SignPayload holds the required and optional fields for the sign payload.
type SignPayload struct {
Expand Down
4 changes: 2 additions & 2 deletions pkg/payload/userdata.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ func (u *UserDataString) UnmarshalJSON(bytes []byte) error {
}

// MarshalJSON marshals the type into JSON.
func (u UserDataString) MarshalJSON() ([]byte, error) {
return []byte("\"" + base64.StdEncoding.EncodeToString([]byte(u)) + "\""), nil
func (u *UserDataString) MarshalJSON() ([]byte, error) {
return []byte("\"" + base64.StdEncoding.EncodeToString([]byte(*u)) + "\""), nil
}
8 changes: 4 additions & 4 deletions pkg/response/collect.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,22 +58,22 @@ type CollectResponse struct {
CompletionData CompletionData `json:"CompletionData"`
}

func (c CollectResponse) String() string {
func (c *CollectResponse) String() string {
return fmt.Sprintf("%#v", c)
}

// IsPending return true if the order is being processed. hintCode describes the status of the order.
func (c CollectResponse) IsPending() bool {
func (c *CollectResponse) IsPending() bool {
return c.Status == StatusPending
}

// IsFailed return true if something went wrong with the order. hintCode describes the error.
func (c CollectResponse) IsFailed() bool {
func (c *CollectResponse) IsFailed() bool {
return c.Status == StatusFailed
}

// IsComplete return true if the order is complete. CompletionData holds User information.
func (c CollectResponse) IsComplete() bool {
func (c *CollectResponse) IsComplete() bool {
return c.Status == StatusComplete
}

Expand Down
Loading

0 comments on commit 5744ba6

Please sign in to comment.