Skip to content

Commit

Permalink
Added support to revoke apps installation token (google#1386)
Browse files Browse the repository at this point in the history
* added support to revoke apps installation token

* updated testcase message
  • Loading branch information
vikkyomkar authored and gmlewis committed Jan 19, 2020
1 parent c74e92b commit 200fc50
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
14 changes: 14 additions & 0 deletions github/apps_installation.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,17 @@ func (s *AppsService) RemoveRepository(ctx context.Context, instID, repoID int64

return s.client.Do(ctx, req, nil)
}

// RevokeInstallationToken revokes an installation token.
//
// GitHub docs: https://developer.github.com/v3/apps/installations/#revoke-an-installation-token
func (s *AppsService) RevokeInstallationToken(ctx context.Context) (*Response, error) {
u := "installation/token"
req, err := s.client.NewRequest("DELETE", u, nil)
if err != nil {
return nil, err
}
req.Header.Set("Accept", mediaTypeRevokeTokenPreview)

return s.client.Do(ctx, req, nil)
}
16 changes: 16 additions & 0 deletions github/apps_installation_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,19 @@ func TestAppsService_RemoveRepository(t *testing.T) {
t.Errorf("Apps.RemoveRepository returned error: %v", err)
}
}

func TestAppsService_RevokeInstallationToken(t *testing.T) {
client, mux, _, teardown := setup()
defer teardown()

mux.HandleFunc("/installation/token", func(w http.ResponseWriter, r *http.Request) {
testMethod(t, r, "DELETE")
testHeader(t, r, "Accept", mediaTypeRevokeTokenPreview)
w.WriteHeader(http.StatusNoContent)
})

_, err := client.Apps.RevokeInstallationToken(context.Background())
if err != nil {
t.Errorf("Apps.RevokeInstallationToken returned error: %v", err)
}
}
3 changes: 3 additions & 0 deletions github/github.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,9 @@ const (

// Media Type values to access preview APIs

// https://developer.github.com/changes/2020-01-10-revoke-installation-token/
mediaTypeRevokeTokenPreview = "application/vnd.github.gambit-preview+json"

// https://developer.github.com/changes/2014-12-09-new-attributes-for-stars-api/
mediaTypeStarringPreview = "application/vnd.github.v3.star+json"

Expand Down

0 comments on commit 200fc50

Please sign in to comment.