Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No refresh token for client_credentials grant #9

Merged
merged 1 commit into from
Mar 29, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 7 additions & 3 deletions oauth/grant_type_client_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,13 @@ func (s *Service) clientCredentialsGrant(w http.ResponseWriter, r *http.Request,
return
}

// Log in the user
accessToken, refreshToken, err := s.Login(client, new(User), scope)
// Create a new access token
accessToken, err := s.GrantAccessToken(
client,
new(User), // empty user
s.cnf.Oauth.AccessTokenLifetime, // expires in
scope,
)
if err != nil {
response.Error(w, err.Error(), http.StatusInternalServerError)
return
Expand All @@ -28,7 +33,6 @@ func (s *Service) clientCredentialsGrant(w http.ResponseWriter, r *http.Request,
ExpiresIn: s.cnf.Oauth.AccessTokenLifetime,
TokenType: TokenType,
Scope: accessToken.Scope,
RefreshToken: refreshToken.Token,
}
response.WriteJSON(w, accessTokenRespone, 200)
}
3 changes: 1 addition & 2 deletions oauth/grant_type_client_credentials_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ func (suite *OauthTestSuite) TestClientCredentialsGrant() {
accessToken := new(AccessToken)
assert.False(suite.T(), suite.db.First(accessToken).RecordNotFound())
refreshToken := new(RefreshToken)
assert.False(suite.T(), suite.db.First(refreshToken).RecordNotFound())
assert.True(suite.T(), suite.db.First(refreshToken).RecordNotFound())

// Check the response body
expected, err := json.Marshal(&AccessTokenResponse{
Expand All @@ -39,7 +39,6 @@ func (suite *OauthTestSuite) TestClientCredentialsGrant() {
ExpiresIn: 3600,
TokenType: TokenType,
Scope: "read_write",
RefreshToken: refreshToken.Token,
})
if assert.NoError(suite.T(), err, "JSON marshalling failed") {
assert.Equal(suite.T(), string(expected), strings.TrimSpace(w.Body.String()))
Expand Down
2 changes: 1 addition & 1 deletion oauth/response.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ type AccessTokenResponse struct {
ExpiresIn int `json:"expires_in"`
TokenType string `json:"token_type"`
Scope string `json:"scope"`
RefreshToken string `json:"refresh_token"`
RefreshToken string `json:"refresh_token,omitempty"`
}

// IntrospectResponse ...
Expand Down