forked from ory/hydra
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
oauth2/revocation: token revocation fails silently with sql store - c…
…loses ory#311
- Loading branch information
Showing
7 changed files
with
97 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
package cli | ||
|
||
import ( | ||
"context" | ||
"fmt" | ||
"github.com/ory-am/hydra/config" | ||
"github.com/ory-am/hydra/oauth2" | ||
"github.com/ory-am/hydra/pkg" | ||
"github.com/spf13/cobra" | ||
"golang.org/x/oauth2/clientcredentials" | ||
) | ||
|
||
type RevocationHandler struct { | ||
Config *config.Config | ||
M *oauth2.HTTPRecovator | ||
} | ||
|
||
func newRevocationHandler(c *config.Config) *RevocationHandler { | ||
return &RevocationHandler{ | ||
Config: c, | ||
M: &oauth2.HTTPRecovator{}, | ||
} | ||
} | ||
|
||
func (h *RevocationHandler) RevokeToken(cmd *cobra.Command, args []string) { | ||
h.M.Endpoint = h.Config.Resolve("/oauth2/revoke") | ||
h.M.Config = &clientcredentials.Config{ | ||
ClientID: h.Config.ClientID, | ||
ClientSecret: h.Config.ClientSecret, | ||
} | ||
|
||
if len(args) != 1 { | ||
fmt.Print(cmd.UsageString()) | ||
return | ||
} | ||
|
||
token := args[0] | ||
err := h.M.RevokeToken(context.Background(), args[0]) | ||
pkg.Must(err, "Could not revoke token: %s", err) | ||
fmt.Printf("Revoked token %s", token) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
// validateCmd represents the validate command | ||
var tokenRevokeCmd = &cobra.Command{ | ||
Use: "revoke <token>", | ||
Short: "Revoke an access or refresh token", | ||
Run: cmdHandler.Revocation.RevokeToken, | ||
} | ||
|
||
func init() { | ||
tokenCmd.AddCommand(tokenRevokeCmd) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters