@@ -332,42 +332,41 @@ func (client *AuthenticationClient) GetNewAccessTokenByRefreshToken(refreshToken
332332 return string (resp .Body ), err
333333}
334334
335- //
336- //func (client *AuthenticationClient) IntrospectToken(token string) (*dto.IntrospectTokenResult, error) {
337- // url := client.options.AppHost + fmt.Sprintf("/%s/token/introspection", client.options.Protocol)
338- // header := map[string]string{
339- // "Content-Type": "application/x-www-form-urlencoded",
340- // }
341- // body := map[string]string{
342- // "token": token,
343- // }
344- // switch client.options.TokenEndPointAuthMethod {
345- // case ClientSecretPost:
346- // body["client_id"] = client.options.AppId
347- // body["client_secret"] = client.options.AppSecret
348- // case ClientSecretBasic:
349- // base64String := "Basic " + base64.StdEncoding.EncodeToString([]byte(fmt.Sprintf("%s:%s", client.options.AppId, client.options.AppSecret)))
350- // header["Authorization"] = base64String
351- // default:
352- // body["client_id"] = client.options.AppId
353- // }
354- // resp, err := client.SendProtocolHttpRequest(&ProtocolRequestOption{
355- // Url: url,
356- // Method: fasthttp.MethodPost,
357- // Headers: client.getReqHeaders(header),
358- // ReqDto: body,
359- // })
360- // println(string(resp.Body))
361- // var response dto.IntrospectTokenResult
362- // if err != nil {
363- // return nil, err
364- // }
365- // err = json.Unmarshal(resp.Body, &response)
366- // if err != nil {
367- // return nil, err
368- // }
369- // return &response, err
370- //}
335+ func (client * AuthenticationClient ) IntrospectToken (token string ) (* dto.IntrospectTokenResult , error ) {
336+ url := client .options .AppHost + fmt .Sprintf ("/%s/token/introspection" , client .options .Protocol )
337+ header := map [string ]string {
338+ "Content-Type" : "application/x-www-form-urlencoded" ,
339+ }
340+ body := map [string ]string {
341+ "token" : token ,
342+ }
343+ switch client .options .TokenEndPointAuthMethod {
344+ case ClientSecretPost :
345+ body ["client_id" ] = client .options .AppId
346+ body ["client_secret" ] = client .options .AppSecret
347+ case ClientSecretBasic :
348+ base64String := "Basic " + base64 .StdEncoding .EncodeToString ([]byte (fmt .Sprintf ("%s:%s" , client .options .AppId , client .options .AppSecret )))
349+ header ["Authorization" ] = base64String
350+ default :
351+ body ["client_id" ] = client .options .AppId
352+ }
353+ resp , err := client .SendProtocolHttpRequest (& ProtocolRequestOption {
354+ Url : url ,
355+ Method : fasthttp .MethodPost ,
356+ Headers : client .getReqHeaders (header ),
357+ ReqDto : body ,
358+ })
359+ println (string (resp .Body ))
360+ var response dto.IntrospectTokenResult
361+ if err != nil {
362+ return nil , err
363+ }
364+ err = json .Unmarshal (resp .Body , & response )
365+ if err != nil {
366+ return nil , err
367+ }
368+ return & response , err
369+ }
371370
372371// RevokeToken
373372// 撤回 Access token 或 Refresh token
0 commit comments