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

feat: Token invalidation #9

Merged
merged 2 commits into from
Sep 30, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -63,3 +63,4 @@ Temporary Items

dist/
/imscli
go.mod.local
36 changes: 36 additions & 0 deletions cmd/invalidate.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package cmd

import (
"github.com/adobe/imscli/ims"
"github.com/spf13/cobra"
)

func invalidateCmd(imsConfig *ims.Config) *cobra.Command {

cmd := &cobra.Command{
Use: "invalidate",
Aliases: []string{"inv"},
Short: "Invalidates a token using the IMS API.",
Long: `Invalidates a token using the IMS API.

This command has no effect by itself, the token type must be specified as a subcommand.
`,
}
cmd.AddCommand(
invalidateAccessTokenCmd(imsConfig),
invalidateRefreshTokenCmd(imsConfig),
invalidateDeviceTokenCmd(imsConfig),
invalidateServiceTokenCmd(imsConfig),
)
return cmd
}
43 changes: 43 additions & 0 deletions cmd/invalidate_access_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package cmd

import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/spf13/cobra"
)

func invalidateAccessTokenCmd(imsConfig *ims.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "accessToken",
Aliases: []string{"acc"},
Short: "Invalidate an access token.",
Long: "Invalidate an access token.",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
cmd.SilenceErrors = true

err := imsConfig.InvalidateToken()
if err != nil {
return fmt.Errorf("error invalidating the access token: %v", err)
}
fmt.Println("Token invalidated successfully.")
return nil
},
}

cmd.Flags().StringVarP(&imsConfig.AccessToken, "accessToken", "t", "", "Access token.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")

return cmd
}
45 changes: 45 additions & 0 deletions cmd/invalidate_device_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package cmd

import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/spf13/cobra"
)

func invalidateDeviceTokenCmd(imsConfig *ims.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "deviceToken",
Aliases: []string{"dev"},
Short: "invalidate a device token.",
Long: "invalidate a device token.",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
cmd.SilenceErrors = true

err := imsConfig.InvalidateToken()
if err != nil {
return fmt.Errorf("error validating the device token: %v", err)
}
fmt.Println("Token invalidated successfully.")
return nil
},
}

cmd.Flags().StringVarP(&imsConfig.DeviceToken, "deviceToken", "t", "", "Device token.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")
cmd.Flags().BoolVarP(&imsConfig.Cascading, "cascading", "a", false,
"Also invalidate all tokens obtained with the device token.")

return cmd
}
45 changes: 45 additions & 0 deletions cmd/invalidate_refresh_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package cmd

import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/spf13/cobra"
)

func invalidateRefreshTokenCmd(imsConfig *ims.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "refreshToken",
Aliases: []string{"ref"},
Short: "Invalidate a refresh token.",
Long: "Invalidate a refresh token.",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
cmd.SilenceErrors = true

err := imsConfig.InvalidateToken()
if err != nil {
return fmt.Errorf("error invalidating the refresh token: %v", err)
}
fmt.Println("Refresh token successfully invalidated.")
return nil
},
}

cmd.Flags().StringVarP(&imsConfig.RefreshToken, "refreshToken", "t", "", "Refresh token.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")
cmd.Flags().BoolVarP(&imsConfig.Cascading, "cascading", "a", false,
"Also invalidate all tokens obtained with the refresh token.")

return cmd
}
46 changes: 46 additions & 0 deletions cmd/invalidate_service_token.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// Copyright 2021 Adobe. All rights reserved.
// This file is licensed to you under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License. You may obtain a copy
// of the License at http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software distributed under
// the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
// OF ANY KIND, either express or implied. See the License for the specific language
// governing permissions and limitations under the License.

package cmd

import (
"fmt"

"github.com/adobe/imscli/ims"
"github.com/spf13/cobra"
)

func invalidateServiceTokenCmd(imsConfig *ims.Config) *cobra.Command {
cmd := &cobra.Command{
Use: "serviceToken",
Aliases: []string{"svc"},
Short: "Invalidate a service token.",
Long: "Invalidate a service token.",
RunE: func(cmd *cobra.Command, args []string) error {
cmd.SilenceUsage = true
cmd.SilenceErrors = true

err := imsConfig.InvalidateToken()
if err != nil {
return fmt.Errorf("error invalidating the service token: %v", err)
}
fmt.Println("Service token successfully invalidated.")
return nil
},
}

cmd.Flags().StringVarP(&imsConfig.RefreshToken, "serviceToken", "t", "", "Service token.")
cmd.Flags().StringVarP(&imsConfig.ClientID, "clientID", "c", "", "IMS Client ID.")
cmd.Flags().StringVarP(&imsConfig.ClientSecret, "clientSecret", "s", "", "IMS Client Secret.")
cmd.Flags().BoolVarP(&imsConfig.Cascading, "cascading", "a", false,
"Also invalidate all tokens obtained with the refresh token.")

return cmd
}
1 change: 1 addition & 0 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ func RootCmd(version string) *cobra.Command {
organizationsCmd(imsConfig),
validateCmd(imsConfig),
exchangeCmd(imsConfig),
invalidateCmd(imsConfig),
)
return cmd
}
5 changes: 3 additions & 2 deletions cmd/validate.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@ import (
func validateCmd(imsConfig *ims.Config) *cobra.Command {

cmd := &cobra.Command{
Use: "validate",
Short: "Validates a token using the IMS API.",
Use: "validate",
Aliases: []string{"val"},
Short: "Validates a token using the IMS API.",
Long: `Verifies if the specified IMS token is valid using the IMS API.

This command has no effect by itself, the token type must be specified as a subcommand.
Expand Down
8 changes: 4 additions & 4 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ module github.com/adobe/imscli
go 1.15

require (
github.com/adobe/ims-go v0.10.1
github.com/adobe/ims-go v0.11.0
github.com/pkg/browser v0.0.0-20210115035449-ce105d075bb4
github.com/spf13/cobra v1.1.3
github.com/spf13/viper v1.7.1
)
github.com/spf13/cobra v1.2.1
github.com/spf13/viper v1.8.1
)
Loading