Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
server
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Analyze
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
m-team
oidc
mytoken
server
Commits
99ecace7
Commit
99ecace7
authored
4 years ago
by
Gabriel Zachmann
Browse files
Options
Downloads
Patches
Plain Diff
client: add info command for decoding token
parent
cf764fb1
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
internal/client/commands/general.go
+0
-2
0 additions, 2 deletions
internal/client/commands/general.go
internal/client/commands/info.go
+38
-0
38 additions, 0 deletions
internal/client/commands/info.go
internal/client/commands/options.go
+3
-0
3 additions, 0 deletions
internal/client/commands/options.go
with
41 additions
and
2 deletions
internal/client/commands/general.go
+
0
−
2
View file @
99ecace7
...
@@ -17,8 +17,6 @@ type generalOptions struct {
...
@@ -17,8 +17,6 @@ type generalOptions struct {
SuperToken
string
`long:"ST" description:"The passed super token is used instead of a stored one"`
SuperToken
string
`long:"ST" description:"The passed super token is used instead of a stored one"`
}
}
type
providerOpt
string
func
(
g
*
generalOptions
)
Check
()
(
*
model
.
Provider
,
string
)
{
func
(
g
*
generalOptions
)
Check
()
(
*
model
.
Provider
,
string
)
{
p
,
pErr
:=
g
.
checkProvider
()
p
,
pErr
:=
g
.
checkProvider
()
if
len
(
g
.
SuperToken
)
>
0
{
if
len
(
g
.
SuperToken
)
>
0
{
...
...
This diff is collapsed.
Click to expand it.
internal/client/commands/info.go
0 → 100644
+
38
−
0
View file @
99ecace7
package
commands
import
(
"bytes"
"encoding/base64"
"encoding/json"
"fmt"
"strings"
"github.com/zachmann/mytoken/internal/utils"
)
// infoCommand is a type for holding and handling the info command
type
infoCommand
struct
{
generalOptions
// EventHistory historyCommand `command:"history" description:"List the event history for this token"`
// SubTree treeCommand `command:"tree" description:"List the tree of subtokens for this token"`
}
// Execute implements the flags.Commander interface
func
(
ic
*
infoCommand
)
Execute
(
args
[]
string
)
error
{
_
,
superToken
:=
ic
.
Check
()
if
!
utils
.
IsJWT
(
superToken
)
{
return
fmt
.
Errorf
(
"The token is not a JWT."
)
}
payload
:=
strings
.
Split
(
superToken
,
"."
)[
1
]
decodedPayload
,
err
:=
base64
.
StdEncoding
.
DecodeString
(
payload
)
if
err
!=
nil
{
return
err
}
var
infoBuffer
bytes
.
Buffer
if
err
=
json
.
Indent
(
&
infoBuffer
,
decodedPayload
,
""
,
" "
);
err
!=
nil
{
return
err
}
info
:=
infoBuffer
.
String
()
fmt
.
Println
(
info
)
return
nil
}
This diff is collapsed.
Click to expand it.
internal/client/commands/options.go
+
3
−
0
View file @
99ecace7
...
@@ -18,6 +18,7 @@ var options struct {
...
@@ -18,6 +18,7 @@ var options struct {
ST
stCommand
ST
stCommand
AT
atCommand
AT
atCommand
Revoke
revokeCommand
Revoke
revokeCommand
Info
infoCommand
}
}
var
parser
*
flags
.
Parser
var
parser
*
flags
.
Parser
...
@@ -35,6 +36,8 @@ func init() {
...
@@ -35,6 +36,8 @@ func init() {
parser
.
AddGroup
(
"Config Options"
,
""
,
&
options
.
ConfigOptions
)
parser
.
AddGroup
(
"Config Options"
,
""
,
&
options
.
ConfigOptions
)
parser
.
AddCommand
(
"AT"
,
"Obtain access token"
,
"Obtain a new OpenID Connect access token"
,
&
options
.
AT
)
parser
.
AddCommand
(
"AT"
,
"Obtain access token"
,
"Obtain a new OpenID Connect access token"
,
&
options
.
AT
)
parser
.
AddCommand
(
"revoke"
,
"Revoke super token"
,
"Revoke a mytoken super token"
,
&
options
.
Revoke
)
parser
.
AddCommand
(
"revoke"
,
"Revoke super token"
,
"Revoke a mytoken super token"
,
&
options
.
Revoke
)
info
,
_
:=
parser
.
AddCommand
(
"info"
,
"Get information about a super token"
,
"Get information about a super token"
,
&
options
.
Info
)
info
.
SubcommandsOptional
=
true
}
}
// Parse parses the command line options and calls the specified command
// Parse parses the command line options and calls the specified command
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment