alipay

package
v0.4.1 Latest Latest
Warning

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

Go to latest
Published: Apr 13, 2024 License: Apache-2.0 Imports: 20 Imported by: 0

Documentation

Overview

Package alipay implements the OAuth2 protocol for authenticating users through Alipay. This package can be used as a reference implementation of an OAuth2 provider for Goth.

Index

Constants

View Source
const (
	KPKCS1Suffix = "-----END RSA PRIVATE KEY-----"

	KPKCS8Suffix = "-----END PRIVATE KEY-----"
)

Variables

View Source
var (
	SandBoxAuthURL = "https://openauth.alipaydev.com/oauth2/publicAppAuthorize.htm"
	SandBoxAPIURL  = "https://openapi.alipaydev.com/gateway.do"

	AuthURL = "https://openauth.alipay.com/oauth2/publicAppAuthorize.htm"
	APIURL  = "https://openapi.alipay.com/gateway.do"
)

These vars define the Authentication, Token, and API URLS for GitHub. If using GitHub enterprise you should change these values before calling New.

View Source
var (
	ErrPrivateKeyFailedToLoad = errors.New("[oauth2s]alipay: private key failed to load")
	ErrPublicKeyFailedToLoad  = errors.New("[oauth2s]alipay: public key failed to load")
)

Functions

func FormatPKCS1PrivateKey added in v0.4.1

func FormatPKCS1PrivateKey(raw string) []byte

func FormatPKCS8PrivateKey added in v0.4.1

func FormatPKCS8PrivateKey(raw string) []byte

func FormatPublicKey added in v0.4.1

func FormatPublicKey(raw string) []byte

func GenRSAKeyWithPKCS1 added in v0.4.1

func GenRSAKeyWithPKCS1(bits int) (privateKey, publicKey []byte, err error)

func GenRSAKeyWithPKCS8 added in v0.4.1

func GenRSAKeyWithPKCS8(bits int) (privateKey, publicKey []byte, err error)

func ParsePKCS1PrivateKey added in v0.4.1

func ParsePKCS1PrivateKey(data []byte) (key *rsa.PrivateKey, err error)

func ParsePKCS8PrivateKey added in v0.4.1

func ParsePKCS8PrivateKey(data []byte) (key *rsa.PrivateKey, err error)

func ParsePublicKey added in v0.4.1

func ParsePublicKey(data []byte) (key *rsa.PublicKey, err error)

func RSADecrypt

func RSADecrypt(ciphertext, key []byte) ([]byte, error)

func RSADecryptWithKey added in v0.4.1

func RSADecryptWithKey(ciphertext []byte, key *rsa.PrivateKey) ([]byte, error)

RSADecryptWithKey 使用私钥 key 对数据 data 进行 RSA 解密

func RSADecryptWithPKCS1 added in v0.4.1

func RSADecryptWithPKCS1(ciphertext, key []byte) ([]byte, error)

RSADecryptWithPKCS1 使用私钥 key 对数据 data 进行 RSA 解密,key 的格式为 pkcs1

func RSADecryptWithPKCS8 added in v0.4.1

func RSADecryptWithPKCS8(ciphertext, key []byte) ([]byte, error)

RSADecryptWithPKCS8 使用私钥 key 对数据 data 进行 RSA 解密,key 的格式为 pkcs8

func RSAEncrypt

func RSAEncrypt(plaintext, key []byte) ([]byte, error)

func RSAEncryptWithKey added in v0.4.1

func RSAEncryptWithKey(plaintext []byte, key *rsa.PublicKey) ([]byte, error)

RSAEncryptWithKey 使用公钥 key 对数据 data 进行 RSA 加密

func RSASignWithKey added in v0.4.1

func RSASignWithKey(plaintext []byte, key *rsa.PrivateKey, hash crypto.Hash) ([]byte, error)

func RSASignWithPKCS1 added in v0.4.1

func RSASignWithPKCS1(plaintext, key []byte, hash crypto.Hash) ([]byte, error)

func RSASignWithPKCS8 added in v0.4.1

func RSASignWithPKCS8(plaintext, key []byte, hash crypto.Hash) ([]byte, error)

func RSAVerify added in v0.4.1

func RSAVerify(ciphertext, sign, key []byte, hash crypto.Hash) error

func RSAVerifyWithKey added in v0.4.1

func RSAVerifyWithKey(ciphertext, sign []byte, key *rsa.PublicKey, hash crypto.Hash) error

func SignRSA

func SignRSA(param url.Values, privateKey *rsa.PrivateKey) (string, error)

func SignRSA2

func SignRSA2(param url.Values, privateKey *rsa.PrivateKey) (string, error)

func SignRSAx

func SignRSAx(param url.Values, privateKey *rsa.PrivateKey, hash crypto.Hash) (string, error)

func VerifyResponseData

func VerifyResponseData(data []byte, signType, sign string, key []byte) error

func VerifySign

func VerifySign(val url.Values, key []byte) error

Types

type Provider

type Provider struct {
	ClientKey   string
	Secret      string
	CallbackURL string
	HTTPClient  *http.Client
	// contains filtered or unexported fields
}

Provider is the implementation of `goth.Provider` for accessing Github.

func New

func New(clientKey, secret, callbackURL string, isProduction bool, scopes ...string) *Provider

New creates a new Github provider, and sets up important connection details. You should always call `github.New` to get a new Provider. Never try to create one manually.

func NewCustomisedURL

func NewCustomisedURL(clientKey, privateKey, callbackURL, authURL string, apiURL string, scopes ...string) *Provider

NewCustomisedURL is similar to New(...) but can be used to set custom URLs to connect to

func (*Provider) BeginAuth

func (p *Provider) BeginAuth(state string) (goth.Session, error)

BeginAuth asks Github for an authentication end-point. documentation https://opensupport.alipay.com/support/helpcenter/166/201602504335?ant_source=zsearch#

func (*Provider) Client

func (p *Provider) Client() *http.Client

func (*Provider) Debug

func (p *Provider) Debug(debug bool)

Debug is sandbox mode

func (*Provider) FetchUser

func (p *Provider) FetchUser(session goth.Session) (goth.User, error)

FetchUser will go to Github and access basic information about the user. documentation https://opendocs.alipay.com/apis/api_2/alipay.user.info.share

func (*Provider) Name

func (p *Provider) Name() string

Name is the name used to retrieve this provider later.

func (*Provider) RefreshToken

func (p *Provider) RefreshToken(refreshToken string) (*oauth2.Token, error)

RefreshToken refresh token is not provided by QQ

func (*Provider) RefreshTokenAvailable

func (p *Provider) RefreshTokenAvailable() bool

RefreshTokenAvailable refresh token is not provided by QQ

func (*Provider) SetName

func (p *Provider) SetName(name string)

SetName is to update the name of the provider (needed in case of multiple providers of 1 type)

func (*Provider) UnmarshalSession

func (p *Provider) UnmarshalSession(data string) (goth.Session, error)

UnmarshalSession will unmarshal a JSON string into a session.

type Session

type Session struct {
	AuthURL      string
	AccessToken  string
	RefreshToken string
	OpenID       string
	Expiry       time.Time
}

Session stores data during the auth process with QQ.

func (*Session) Authorize

func (s *Session) Authorize(provider goth.Provider, params goth.Params) (string, error)

Authorize the session with Github and return the access token to be stored for future use. ?state=state&app_id=hide&source=alipay_wallet&userOutputs=auth_user&scope=auth_user&alipay_token=&auth_code=7b7022f35fff49b896d0251bc763VX39 documentation https://opendocs.alipay.com/apis/api_9/alipay.system.oauth.token

func (Session) GetAuthURL

func (s Session) GetAuthURL() (string, error)

GetAuthURL will return the URL set by calling the `BeginAuth` function on the QQ provider.

func (Session) Marshal

func (s Session) Marshal() string

Marshal the session into a string

func (Session) String

func (s Session) String() string

Jump to

Keyboard shortcuts

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