Skip to content

Commit

Permalink
Merge pull request #197 from oriengy/master
Browse files Browse the repository at this point in the history
modifed the implementation of the refresh token process
  • Loading branch information
LyricTian authored Sep 5, 2021
2 parents 99cf16d + c38c6b3 commit fa969a0
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 13 deletions.
8 changes: 5 additions & 3 deletions manage/manage_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,9 +93,11 @@ func testManager(tgr *oauth2.TokenGenerateRequest, manager oauth2.Manager) {
So(err, ShouldBeNil)
So(rinfo.GetClientID(), ShouldEqual, atParams.ClientID)

atParams.Refresh = refreshToken
atParams.Scope = "owner"
rti, err := manager.RefreshAccessToken(ctx, atParams)
refreshParams := &oauth2.TokenGenerateRequest{
Refresh: refreshToken,
Scope: "owner",
}
rti, err := manager.RefreshAccessToken(ctx, refreshParams)
So(err, ShouldBeNil)

refreshAT := rti.GetAccess()
Expand Down
12 changes: 2 additions & 10 deletions manage/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -360,22 +360,14 @@ func (m *Manager) GenerateAccessToken(ctx context.Context, gt oauth2.GrantType,

// RefreshAccessToken refreshing an access token
func (m *Manager) RefreshAccessToken(ctx context.Context, tgr *oauth2.TokenGenerateRequest) (oauth2.TokenInfo, error) {
cli, err := m.GetClient(ctx, tgr.ClientID)
ti, err := m.LoadRefreshToken(ctx, tgr.Refresh)
if err != nil {
return nil, err
} else if cliPass, ok := cli.(oauth2.ClientPasswordVerifier); ok {
if !cliPass.VerifyPassword(tgr.ClientSecret) {
return nil, errors.ErrInvalidClient
}
} else if tgr.ClientSecret != cli.GetSecret() {
return nil, errors.ErrInvalidClient
}

ti, err := m.LoadRefreshToken(ctx, tgr.Refresh)
cli, err := m.GetClient(ctx, ti.GetClientID())
if err != nil {
return nil, err
} else if ti.GetClientID() != tgr.ClientID {
return nil, errors.ErrInvalidRefreshToken
}

oldAccess, oldRefresh := ti.GetAccess(), ti.GetRefresh()
Expand Down

0 comments on commit fa969a0

Please sign in to comment.