Skip to content

Commit

Permalink
Add GetJwtToken request to the regular Erply Client
Browse files Browse the repository at this point in the history
  • Loading branch information
tarmo-randma committed May 13, 2020
1 parent 2d1b7b3 commit f36ed45
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 1 deletion.
1 change: 1 addition & 0 deletions pkg/api/auth/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ type (
Provider interface {
VerifyIdentityToken(ctx context.Context, jwt string) (*SessionInfo, error)
GetIdentityToken(ctx context.Context) (*IdentityToken, error)
GetJWTToken(ctx context.Context) (*JwtToken, error)
}

//interface only for partner tokens
Expand Down
23 changes: 22 additions & 1 deletion pkg/api/auth/tokenRequsts.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"context"
"encoding/json"
"fmt"
"strconv"

"github.com/erply/api-go-wrapper/internal/common"
erro "github.com/erply/api-go-wrapper/internal/errors"
"strconv"
)

//VerifyIdentityToken ...
Expand Down Expand Up @@ -54,6 +55,26 @@ func (cli *Client) GetIdentityToken(ctx context.Context) (*IdentityToken, error)
return &res.Result, nil
}

//GetJWTToken executes the getJWTToken query (https://learn-api.erply.com/requests/getjwttoken).
func (cli *Client) GetJWTToken(ctx context.Context) (*JwtToken, error) {

resp, err := cli.SendRequest(ctx, "getJwtToken", map[string]string{})
if err != nil {
return nil, err
}
var res JwtTokenResponse

err = json.NewDecoder(resp.Body).Decode(&res)
if err != nil {
return nil, erro.NewFromError("error decoding GetJWTToken response", err)
}
if !common.IsJSONResponseOK(&res.Status) {
return nil, erro.NewErplyError(strconv.Itoa(res.Status.ErrorCode), res.Status.Request+": "+res.Status.ResponseStatus)
}

return &res.Records, nil
}

//only for partnerClient
func (cli *PartnerClient) GetJWTToken(ctx context.Context) (*JwtToken, error) {

Expand Down

0 comments on commit f36ed45

Please sign in to comment.