fix: user wechat auth
This commit is contained in:
@@ -18,10 +18,10 @@ const (
|
||||
)
|
||||
|
||||
type BaseClaims struct {
|
||||
OpenID string `json:"open_id,omitempty"`
|
||||
Tenant string `json:"tenant,omitempty"`
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
TenantID int64 `json:"tenant_id,omitempty"`
|
||||
UserID int64 `json:"user_id,omitempty"`
|
||||
TenantID *int64 `json:"tenant_id,omitempty"`
|
||||
OpenID *string `json:"open_id,omitempty"`
|
||||
Tenant *string `json:"tenant,omitempty"`
|
||||
}
|
||||
|
||||
// Custom claims structure
|
||||
|
||||
@@ -6,6 +6,9 @@ import (
|
||||
"net/url"
|
||||
"sort"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"backend/pkg/oauth"
|
||||
|
||||
"github.com/imroc/req/v3"
|
||||
"github.com/pkg/errors"
|
||||
@@ -123,6 +126,8 @@ func (we *Client) ScopeAuthorizeURL(opts ...ScopeAuthorizeURLOptions) (*url.URL,
|
||||
return u, nil
|
||||
}
|
||||
|
||||
var _ oauth.OAuthInfo = (*AuthorizeAccessToken)(nil)
|
||||
|
||||
type AuthorizeAccessToken struct {
|
||||
ErrorResponse
|
||||
AccessToken string `json:"access_token,omitempty"`
|
||||
@@ -134,6 +139,31 @@ type AuthorizeAccessToken struct {
|
||||
Unionid string `json:"unionid,omitempty"`
|
||||
}
|
||||
|
||||
// GetAccessToken implements oauth.OAuthInfo.
|
||||
func (a *AuthorizeAccessToken) GetAccessToken() string {
|
||||
return a.AccessToken
|
||||
}
|
||||
|
||||
// GetExpiredAt implements oauth.OAuthInfo.
|
||||
func (a *AuthorizeAccessToken) GetExpiredAt() time.Time {
|
||||
return time.Now().Add(time.Duration(a.ExpiresIn) * time.Second)
|
||||
}
|
||||
|
||||
// GetOpenID implements oauth.OAuthInfo.
|
||||
func (a *AuthorizeAccessToken) GetOpenID() string {
|
||||
return a.Openid
|
||||
}
|
||||
|
||||
// GetRefreshToken implements oauth.OAuthInfo.
|
||||
func (a *AuthorizeAccessToken) GetRefreshToken() string {
|
||||
return a.RefreshToken
|
||||
}
|
||||
|
||||
// GetUnionID implements oauth.OAuthInfo.
|
||||
func (a *AuthorizeAccessToken) GetUnionID() string {
|
||||
return a.Unionid
|
||||
}
|
||||
|
||||
func (we *Client) AuthorizeCode2Token(code string) (*AuthorizeAccessToken, error) {
|
||||
params := we.wrapParams(map[string]string{
|
||||
"code": code,
|
||||
|
||||
Reference in New Issue
Block a user