sberbank_id

package module
v0.0.0-...-92cad06 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: 9 Imported by: 0

README

Sberbank ID

Sberbank ID client implementation.

Usage

Install module

go get github.com/everbslab/sberbank_id

Apply in your app:

    var SbidClientId = "0123456.....12345678901"
    var SbidClientSecret = "Q....Y"

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

    authcode, err := sbc.AuthRequest()
    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 {
        logInfo(fmt.Sprintf("**** Personal data map: %v", 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

View Source
const (
	AuthorizeAccessTokenUrl = "http://45.12.238.224:8181/CSAFront/oidc/sberbank_id/authorize.do"
	TokenAuthorizeUrl       = "http://45.12.238.224:8181/ru/prod/tokens/v2/oidc"
	PersonalDataUrl         = "http://45.12.238.224:8181/ru/prod/sberbankid/v2.1/userInfo"
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Config

type Config struct {
	Scope       string
	RedirectUrl string

	DebugMode bool
	// contains filtered or unexported fields
}

Config is a structure to keep instance parameters for httpClient requests

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 SberbankIdClient

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

SberbankIdClient represents the main struct of a client for Sbebank ID API

func New

func New(clientId, clientSecret string, config *Config) *SberbankIdClient

func (*SberbankIdClient) AuthRequest

func (c *SberbankIdClient) AuthRequest() (string, error)

func (*SberbankIdClient) GetPersonalData

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

func (*SberbankIdClient) GetToken

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

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