sberbankid

package module
v0.0.0-...-44a4f6e Latest Latest
Warning

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

Go to latest
Published: Oct 19, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

README

Sberbank ID

Sberbank ID implementation.

Project status

Go Report Card made-with-Go

Install

go get github.com/everbslab/sberbankid

Usage

Apply in your app:

    var (
        SbidClientId = "0123456.....12345678901"    // yours client id
        SbidClientSecret = "Q....Y"                 // your client secret
    )

    sbc := sberbankid.NewClient(SbidClientId, SbidClientSecret, &sberbank_id.Config{
        Scope:       "openid name snils gender mobile inn maindoc birthdate verified",
        RedirectUrl: "http://127.0.0.1:8080/login",
        Env:         sberbankid.EnvSandbox,
        VerboseMode: true,
    })

    authcode, err := sbc.AuthRequest("Q0002", "Password2")
    if err != nil {
        log.Fatal(err)
    }

    token, err := sbc.GetToken(authcode)
    if err != nil {
        log.Fatal(err)
    }

    if pdata, err := sbc.GetPersonalData(token); err == nil {
        log.Printf("**** Personal data map: %v\n", pdata)
    } else {
        log.Fatal(err)
    }

Result will be data map with Personal Data received from Sberbank according to defined scope.

{"iss":"http://45.12.238.224:8181/ru/prod/tokens/v2/oidc","sub":"022fa8480ff243439f5887ab5a847c1b","aud":"012345670123abcd0123012345678901","birthdate":"1980.01.01","identificaton":{"series":"0001","number":"000001","issuedBy":null,
"issuedDate":"2000.01.01","code":"001-001"},"inn":{"number":"0000000001"},"snils":{"number":"0000001"},"gender":1,"verified":1,"family_name":"Иванов","given_name":"Иван","middle_name":"Иванович","phone_number":"+79001000001"}
2020/10/19 15:55:37 **** Personal data: &map[aud:012345670123abcd0123012345678901 birthdate:1980.01.01 family_name:Иванов gender:1 given_name:Иван identificaton:map[code:001-001 issuedBy:<nil> issuedDate:2000.01.01 number:000001 ser
ies:0001] inn:map[number:0000000001] iss:http://45.12.238.224:8181/ru/prod/tokens/v2/oidc middle_name:Иванович phone_number:+79001000001 snils:map[number:0000001] sub:022fa8480ff243439f5887ab5a847c1b verified:1]

Protocol specifications:

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Client

type Client struct {
	HTTPCient *http.Client
	// contains filtered or unexported fields
}

Client represents the main struct of a client for Sbebank ID API.

func NewClient

func NewClient(clientID, clientSecret string, config *Config) *Client

NewClient initializes Client instance.

func (*Client) AuthRequest

func (c *Client) AuthRequest(login, pass string) (string, error)

AuthRequest performs logging to Sberbank's endpoint to fetch Auth code.

func (*Client) GetPersonalData

func (c *Client) GetPersonalData(token *TokenResponse) (*PersonData, error)

GetPersonalData fetches customer personal data using TokenResponse.

func (*Client) GetToken

func (c *Client) GetToken(authcode string) (*TokenResponse, error)

GetToken requests by API Token.

type Config

type Config struct {
	Scope       string
	RedirectURL string

	Env         Environment
	VerboseMode bool
	// contains filtered or unexported fields
}

Config is a structure to keep instance parameters for httpClient requests.

type Environment

type Environment int

Environment type.

const (

	// EnvSandbox Sandbox environment.
	EnvSandbox Environment = 1 << iota
	// EnvDev DEV environment.
	EnvDev
	// EnvProd PROD environment.
	EnvProd
)

type PersonData

type PersonData map[string]interface{}

PersonData represents Personal Data response. JSON formatted.

type SberCredentials

type SberCredentials struct {
	ClientID     string
	ClientSecret string
}

SberCredentials is a struct to store user credentials for Sberbank ID API.

type TokenResponse

type TokenResponse struct {
	AccessToken string `json:"access_token"`
	TokenType   string `json:"token_type"`
	ExpiresIn   int    `json:"expires_in,omitempty"`
	Scope       string `json:"scope"`
	IDToken     string `json:"id_token"`
}

TokenResponse represents OAuth token response.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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