Skip to content

Commit

Permalink
use buffer
Browse files Browse the repository at this point in the history
  • Loading branch information
CNLHC committed Dec 5, 2022
1 parent 03b1ea4 commit 77d822e
Showing 1 changed file with 18 additions and 21 deletions.
39 changes: 18 additions & 21 deletions selfservice/strategy/oidc/provider_lark.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@
package oidc

import (
"bytes"
"context"
"encoding/json"
"net/url"
"strings"
"time"

"github.com/hashicorp/go-retryablehttp"
Expand All @@ -32,23 +32,6 @@ func NewProviderLark(
}
}

type larkClaim struct {
Sub string `json:"sub"`
Name string `json:"name"`
Picture string `json:"picture"`
OpenID string `json:"open_id"`
UnionID string `json:"union_id"`
EnName string `json:"en_name"`
TenantKey string `json:"tenant_key"`
AvatarURL string `json:"avatar_url"`
AvatarThumb string `json:"avatar_thumb"`
AvatarMiddle string `json:"avatar_middle"`
AvatarBig string `json:"avatar_big"`
Email string `json:"email"`
UserID string `json:"user_id"`
Mobile string `json:"mobile"`
}

func (g *ProviderLark) Config() *Configuration {
return g.config
}
Expand All @@ -72,6 +55,22 @@ func (g *ProviderLark) OAuth2(ctx context.Context) (*oauth2.Config, error) {
}

func (g *ProviderLark) Claims(ctx context.Context, exchange *oauth2.Token, query url.Values) (*Claims, error) {
type larkClaim struct {
Sub string `json:"sub"`
Name string `json:"name"`
Picture string `json:"picture"`
OpenID string `json:"open_id"`
UnionID string `json:"union_id"`
EnName string `json:"en_name"`
TenantKey string `json:"tenant_key"`
AvatarURL string `json:"avatar_url"`
AvatarThumb string `json:"avatar_thumb"`
AvatarMiddle string `json:"avatar_middle"`
AvatarBig string `json:"avatar_big"`
Email string `json:"email"`
UserID string `json:"user_id"`
Mobile string `json:"mobile"`
}
var (
userEndpoint = "https://passport.feishu.cn/suite/passport/oauth/userinfo"
accessToken = exchange.AccessToken
Expand Down Expand Up @@ -146,13 +145,11 @@ func (g *ProviderLark) Exchange(ctx context.Context, code string, opts ...oauth2
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))
}

r := strings.NewReader(string(bs))
client := g.reg.HTTPClient(ctx, httpx.ResilientClientDisallowInternalIPs())
req, err := retryablehttp.NewRequest("POST", conf.Endpoint.TokenURL, r)
req, err := retryablehttp.NewRequest("POST", conf.Endpoint.TokenURL, bytes.NewBuffer(bs))
if err != nil {
return nil, errors.WithStack(herodot.ErrInternalServerError.WithReasonf("%s", err))
}

req.Header.Add("Content-Type", "application/json;charset=UTF-8")

resp, err := client.Do(req)
Expand Down

0 comments on commit 77d822e

Please sign in to comment.