bankid

package module
v0.0.0-...-840c301 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 5, 2021 License: MIT Imports: 9 Imported by: 0

README

Swedish BankID API client for Go

The client is tested but not battle tested. For detailed API documentation go to https://www.bankid.com.

Install

No versions supported at the moment only master targeting BankID API version 5.1.

Install

go get github.com/ahrberg/bankid

Usage

import "github.com/ahrberg/bankid"

// Client configured with certificates
// use bankid.NewClient to specify a custom client
client := bankid.NewCertClient("./ca_cert.pem", "./client_cert.pem", "./client_key.pem")

// Make an auth request
ctx = context.Background()

params := AuthRequest{
		EndUserIp: "192.168.0.1",
    }

res, err := client.Auth(ctx, &params)

Errors

Response errors are returned using the following struct. For error details see BankID error documentation.

type ErrorResponse struct {
	// HTTP response that caused this error
	Response  *http.Response
	ErrorCode string `json:"errorCode"`
	Details   string `json:"details"`
}

Documentation

Overview

Package bankid is a BankID API client for Go. For detailed API documentation checkout https://www.bankid.com/

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewTransport

func NewTransport(caCertFilename string, clientCertFilename string, clientCertKeyFilename string) (*http.Transport, error)

NewTransport creates a http.Transport custom CA and mTLS certificate. Only the specified CA will be used.

Types

type AuthRequest

type AuthRequest struct {
	// The user IP address as seen by RP. String. IPv4 and IPv6 is allowed.
	// Note the importance of using the correct IP address.
	// It must be the IP address representing the user agent (the end user device)
	// as seen by the RP. If there is a proxy for inbound traffic, special considerations
	// may need to be taken to get the correct address.
	// In some use cases the IP address is not available,
	// for instance for voice based services. In this case,
	// the internal representation of those systems IP address is ok to use.
	EndUserIp string `json:"endUserIp"`
	// The personal number of the user. String. 12 digits.
	// Century must be included. If the personal number is excluded,
	// the client must be started with the autoStartToken returned in the response.
	PersonalNumber string `json:"personalNumber,omitempty"`
	// Requirements on how the auth or sign order must be performed.
	Requirement string `json:"requirement,omitempty"`
}

type AuthResponse

type AuthResponse struct {
	OrderRef       string `json:"orderRef"`
	AutoStartToken string `json:"autoStartToken"`
	QrStartToken   string `json:"qrStartToken"`
	QrStartSecret  string `json:"qrStartSecret"`
}

type CancelRequest

type CancelRequest struct {
	// The orderRef returned from auth or sign.
	OrderRef string `json:"orderRef"`
}

type CancelResponse

type CancelResponse struct {
}

type Client

type Client struct {
	BaseUrl    string
	UserAgent  string
	HTTPClient *http.Client
}

func NewCertClient

func NewCertClient(caCertFilename string, clientCertFilename string, clientCertKeyFilename string) (*Client, error)

NewCertClient returns a BankID API client with given certificates

func NewClient

func NewClient(httpClient *http.Client) (*Client, error)

NewClient returns a BankID API client using the given http.Client.

Use this function if you want to specify your own client, else use NewCertClient.

func (*Client) Auth

func (c *Client) Auth(ctx context.Context, params *AuthRequest) (*AuthResponse, error)

func (*Client) Cancel

func (c *Client) Cancel(ctx context.Context, params *CancelRequest) (*CancelResponse, error)

func (*Client) Collect

func (c *Client) Collect(ctx context.Context, params *CollectRequest) (*CollectResponse, error)

func (*Client) Sign

func (c *Client) Sign(ctx context.Context, params *SignRequest) (*SignResponse, error)

type CollectRequest

type CollectRequest struct {
	// The orderRef returned from auth or sign.
	OrderRef string `json:"orderRef"`
}

type CollectResponse

type CollectResponse struct {
	OrderRef       string `json:"orderRef"`
	Status         string `json:"status"`
	HintCode       string `json:"hintCode"`
	CompletionData struct {
		User struct {
			PersonalNumber string `json:"personalNumber"`
			Name           string `json:"name"`
			GivenName      string `json:"givenName"`
			Surname        string `json:"surname"`
		} `json:"user"`
		Device struct {
			IPAddress string `json:"ipAddress"`
		} `json:"device"`
		Cert struct {
			NotBefore string `json:"notBefore"`
			NotAfter  string `json:"notAfter"`
		} `json:"cert"`
		Signature    string `json:"signature"`
		OcspResponse string `json:"ocspResponse"`
	} `json:"completionData"`
}

type ErrorResponse

type ErrorResponse struct {
	// HTTP response that caused this error
	Response  *http.Response
	ErrorCode string `json:"errorCode"`
	Details   string `json:"details"`
}

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

type SignRequest

type SignRequest struct {
	// The user IP address as seen by RP. String. IPv4 and IPv6 is allowed.
	// Note the importance of using the correct IP address.
	// It must be the IP address representing the user agent (the end user device)
	// as seen by the RP. If there is a proxy for inbound traffic, special considerations
	// may need to be taken to get the correct address.
	// In some use cases the IP address is not available,
	// for instance for voice based services. In this case,
	// the internal representation of those systems IP address is ok to use.
	EndUserIp string `json:"endUserIp"`
	// The personal number of the user. String. 12 digits.
	// Century must be included. If the personal number is excluded,
	// the client must be started with the autoStartToken returned in the response.
	PersonalNumber string `json:"personalNumber,omitempty"`
	// Requirements on how the auth or sign order must be performed.
	Requirement string `json:"requirement,omitempty"`
	// The text to be displayed and signed. String. The text can be formatted using
	// CR, LF and CRLF for new lines. The text must be encoded as UTF-8 and then
	// base 64 encoded. 1--40 000 characters after base 64 encoding.
	UserVisibleData string `json:"userVisibleData,omitempty"`
	// Data not displayed to the user. String. The value must be base 64-encoded.
	// 1-200 000 characters after base 64-encoding.
	UserNonVisibleData string `json:"userNonVisibleData,omitempty"`
	// If present, and set to “simpleMarkdownV1”, this parameter indicates that
	// userVisibleData holds formatting characters which, if used correctly,
	// will make the text displayed with the user nicer to look at.
	UserVisibleDataFormat string `json:"userVisibleDataFormat,omitempty"`
}

type SignResponse

type SignResponse struct {
	OrderRef       string `json:"orderRef"`
	AutoStartToken string `json:"autoStartToken"`
	QrStartToken   string `json:"qrStartToken"`
	QrStartSecret  string `json:"qrStartSecret"`
}

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL