diff --git a/auth/login.go b/auth/login.go index c86471b..b7108b9 100644 --- a/auth/login.go +++ b/auth/login.go @@ -18,6 +18,43 @@ import ( "net/url" ) +// CallbackLoginPath computes a request path to the callback action of login. +func CallbackLoginPath() string { + + return fmt.Sprintf("/api/login/callback") +} + +// Authorization code callback +func (c *Client) CallbackLogin(ctx context.Context, path string, code *string, state *string) (*http.Response, error) { + req, err := c.NewCallbackLoginRequest(ctx, path, code, state) + if err != nil { + return nil, err + } + return c.Client.Do(ctx, req) +} + +// NewCallbackLoginRequest create the request corresponding to the callback action endpoint of the login resource. +func (c *Client) NewCallbackLoginRequest(ctx context.Context, path string, code *string, state *string) (*http.Request, error) { + scheme := c.Scheme + if scheme == "" { + scheme = "http" + } + u := url.URL{Host: c.Host, Scheme: scheme, Path: path} + values := u.Query() + if code != nil { + values.Set("code", *code) + } + if state != nil { + values.Set("state", *state) + } + u.RawQuery = values.Encode() + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return nil, err + } + return req, nil +} + // LoginLoginPath computes a request path to the login action of login. func LoginLoginPath() string { diff --git a/auth/logout.go b/auth/logout.go index 4ff9773..9119d0b 100644 --- a/auth/logout.go +++ b/auth/logout.go @@ -25,8 +25,8 @@ func LogoutLogoutPath() string { } // Logout user -func (c *Client) LogoutLogout(ctx context.Context, path string, redirect *string) (*http.Response, error) { - req, err := c.NewLogoutLogoutRequest(ctx, path, redirect) +func (c *Client) LogoutLogout(ctx context.Context, path string, redirect *string, referer *string) (*http.Response, error) { + req, err := c.NewLogoutLogoutRequest(ctx, path, redirect, referer) if err != nil { return nil, err } @@ -34,7 +34,7 @@ func (c *Client) LogoutLogout(ctx context.Context, path string, redirect *string } // NewLogoutLogoutRequest create the request corresponding to the logout action endpoint of the logout resource. -func (c *Client) NewLogoutLogoutRequest(ctx context.Context, path string, redirect *string) (*http.Request, error) { +func (c *Client) NewLogoutLogoutRequest(ctx context.Context, path string, redirect *string, referer *string) (*http.Request, error) { scheme := c.Scheme if scheme == "" { scheme = "http" @@ -49,5 +49,10 @@ func (c *Client) NewLogoutLogoutRequest(ctx context.Context, path string, redire if err != nil { return nil, err } + header := req.Header + if referer != nil { + + header.Set("Referer", *referer) + } return req, nil } diff --git a/auth/media_types.go b/auth/media_types.go index d90c182..ff00d74 100644 --- a/auth/media_types.go +++ b/auth/media_types.go @@ -67,30 +67,6 @@ func (c *Client) DecodeAuthToken(resp *http.Response) (*AuthToken, error) { return &decoded, err } -// AuthTokenCollection is the media type for an array of AuthToken (default view) -// -// Identifier: application/vnd.authtoken+json; type=collection; view=default -type AuthTokenCollection []*AuthToken - -// Validate validates the AuthTokenCollection media type instance. -func (mt AuthTokenCollection) Validate() (err error) { - for _, e := range mt { - if e != nil { - if err2 := e.Validate(); err2 != nil { - err = goa.MergeErrors(err, err2) - } - } - } - return -} - -// DecodeAuthTokenCollection decodes the AuthTokenCollection instance encoded in resp body. -func (c *Client) DecodeAuthTokenCollection(resp *http.Response) (AuthTokenCollection, error) { - var decoded AuthTokenCollection - err := c.Decoder.Decode(&decoded, resp.Body, resp.Header.Get("Content-Type")) - return decoded, err -} - // Holds the response to a cluster list request (default view) // // Identifier: application/vnd.clusterlist+json; view=default diff --git a/auth/token.go b/auth/token.go index 7dec4db..977695c 100644 --- a/auth/token.go +++ b/auth/token.go @@ -98,6 +98,39 @@ func (c *Client) NewExchangeTokenRequest(ctx context.Context, path string, paylo return req, nil } +// LinkCallbackTokenPath computes a request path to the LinkCallback action of token. +func LinkCallbackTokenPath() string { + + return fmt.Sprintf("/api/token/link/callback") +} + +// Callback from an external oauth2 resource provider such as GitHub as part of user's account linking +func (c *Client) LinkCallbackToken(ctx context.Context, path string, code string, state string) (*http.Response, error) { + req, err := c.NewLinkCallbackTokenRequest(ctx, path, code, state) + if err != nil { + return nil, err + } + return c.Client.Do(ctx, req) +} + +// NewLinkCallbackTokenRequest create the request corresponding to the LinkCallback action endpoint of the token resource. +func (c *Client) NewLinkCallbackTokenRequest(ctx context.Context, path string, code string, state string) (*http.Request, error) { + scheme := c.Scheme + if scheme == "" { + scheme = "http" + } + u := url.URL{Host: c.Host, Scheme: scheme, Path: path} + values := u.Query() + values.Set("code", code) + values.Set("state", state) + u.RawQuery = values.Encode() + req, err := http.NewRequest("GET", u.String(), nil) + if err != nil { + return nil, err + } + return req, nil +} + // RetrieveTokenPath computes a request path to the Retrieve action of token. func RetrieveTokenPath() string { @@ -211,68 +244,6 @@ func (c *Client) NewAuditTokenRequest(ctx context.Context, path string, resource return req, nil } -// CallbackTokenPath computes a request path to the callback action of token. -func CallbackTokenPath() string { - - return fmt.Sprintf("/api/token/link/callback") -} - -// Callback from an external oauth2 resource provider such as GitHub as part of user's account linking -func (c *Client) CallbackToken(ctx context.Context, path string, code string, state string) (*http.Response, error) { - req, err := c.NewCallbackTokenRequest(ctx, path, code, state) - if err != nil { - return nil, err - } - return c.Client.Do(ctx, req) -} - -// NewCallbackTokenRequest create the request corresponding to the callback action endpoint of the token resource. -func (c *Client) NewCallbackTokenRequest(ctx context.Context, path string, code string, state string) (*http.Request, error) { - scheme := c.Scheme - if scheme == "" { - scheme = "http" - } - u := url.URL{Host: c.Host, Scheme: scheme, Path: path} - values := u.Query() - values.Set("code", code) - values.Set("state", state) - u.RawQuery = values.Encode() - req, err := http.NewRequest("GET", u.String(), nil) - if err != nil { - return nil, err - } - return req, nil -} - -// GenerateTokenPath computes a request path to the generate action of token. -func GenerateTokenPath() string { - - return fmt.Sprintf("/api/token/generate") -} - -// Generate a set of Tokens for different Auth levels. NOT FOR PRODUCTION. Only available if server is running in dev mode -func (c *Client) GenerateToken(ctx context.Context, path string) (*http.Response, error) { - req, err := c.NewGenerateTokenRequest(ctx, path) - if err != nil { - return nil, err - } - return c.Client.Do(ctx, req) -} - -// NewGenerateTokenRequest create the request corresponding to the generate action endpoint of the token resource. -func (c *Client) NewGenerateTokenRequest(ctx context.Context, path string) (*http.Request, error) { - scheme := c.Scheme - if scheme == "" { - scheme = "http" - } - u := url.URL{Host: c.Host, Scheme: scheme, Path: path} - req, err := http.NewRequest("GET", u.String(), nil) - if err != nil { - return nil, err - } - return req, nil -} - // KeysTokenPath computes a request path to the keys action of token. func KeysTokenPath() string { diff --git a/source_commit.txt b/source_commit.txt index a19a2f5..a0a8f81 100644 --- a/source_commit.txt +++ b/source_commit.txt @@ -1 +1 @@ -a07405a243956b7c6a56e69fe2b38cce7f5abbf7 +3a44ba7ddd1ebe96cae360c1cecfb7f7264d69d6 diff --git a/tool/cli/commands.go b/tool/cli/commands.go index fbc3193..3f3a750 100644 --- a/tool/cli/commands.go +++ b/tool/cli/commands.go @@ -128,6 +128,15 @@ type ( PrettyPrint bool } + // CallbackLoginCommand is the command line data structure for the callback action of login + CallbackLoginCommand struct { + // Authorization code + Code string + // state value + State string + PrettyPrint bool + } + // LoginLoginCommand is the command line data structure for the login action of login LoginLoginCommand struct { // The name of the api client which is requesting a token @@ -143,6 +152,7 @@ type ( LogoutLogoutCommand struct { // URL to be redirected to after successful logout. If not set then will redirect to the referrer instead. Redirect string + Referer string PrettyPrint bool } @@ -297,6 +307,15 @@ type ( PrettyPrint bool } + // LinkCallbackTokenCommand is the command line data structure for the LinkCallback action of token + LinkCallbackTokenCommand struct { + // Code provided by an external oauth2 resource provider + Code string + // State generated by the link request + State string + PrettyPrint bool + } + // RetrieveTokenCommand is the command line data structure for the Retrieve action of token RetrieveTokenCommand struct { // The resource for which the external token is being fetched, example https://github.com or https://api.starter-us-east-2.openshift.com @@ -322,20 +341,6 @@ type ( PrettyPrint bool } - // CallbackTokenCommand is the command line data structure for the callback action of token - CallbackTokenCommand struct { - // Code provided by an external oauth2 resource provider - Code string - // State generated by the link request - State string - PrettyPrint bool - } - - // GenerateTokenCommand is the command line data structure for the generate action of token - GenerateTokenCommand struct { - PrettyPrint bool - } - // KeysTokenCommand is the command line data structure for the keys action of token KeysTokenCommand struct { // Key format. If set to "jwk" (used by default) then JSON Web Key format will be used. If "pem" then a PEM-like format (PEM without header and footer) will be used. @@ -480,9 +485,9 @@ Payload example: } ], "included": [ - "c3d4ab19-6e68-4681-a613-0cc5952e49be", - "c3d4ab19-6e68-4681-a613-0cc5952e49be", - "c3d4ab19-6e68-4681-a613-0cc5952e49be" + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6", + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6", + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6" ] }`, RunE: func(cmd *cobra.Command, args []string) error { return tmp3.Run(c, args) }, @@ -566,9 +571,9 @@ Payload example: tmp7.RegisterFlags(sub, c) sub.PersistentFlags().BoolVar(&tmp7.PrettyPrint, "pp", false, "Pretty print response body") command.AddCommand(sub) - tmp8 := new(CallbackTokenCommand) + tmp8 := new(CallbackLoginCommand) sub = &cobra.Command{ - Use: `token ["/api/token/link/callback"]`, + Use: `login ["/api/login/callback"]`, Short: ``, RunE: func(cmd *cobra.Command, args []string) error { return tmp8.Run(c, args) }, } @@ -589,7 +594,7 @@ Payload example: Payload example: { - "name": "Saepe voluptas ex sit voluptate." + "name": "Consequatur consectetur et." }`, RunE: func(cmd *cobra.Command, args []string) error { return tmp9.Run(c, args) }, } @@ -614,8 +619,8 @@ Payload example: Payload example: { - "name": "Sequi hic perspiciatis nobis perspiciatis quibusdam.", - "space_id": "Numquam ut odit vel." + "name": "Molestias laudantium sequi hic perspiciatis nobis.", + "space_id": "Quibusdam dolor numquam ut odit." }`, RunE: func(cmd *cobra.Command, args []string) error { return tmp11.Run(c, args) }, } @@ -633,8 +638,8 @@ Payload example: { "data": { "attributes": { - "approved": true, - "bio": "Placeat error sed qui.", + "approved": false, + "bio": "Magnam placeat error sed qui.", "cluster": "Ad inventore at omnis.", "company": "Commodi voluptatem alias dolore est.", "contextInformation": { @@ -685,17 +690,16 @@ Payload example: { "data": [ { - "identity-id": "Doloribus recusandae non.", - "member": true, + "identity-id": "Consequatur maiores at cupiditate.", + "member": false, "roles": [ - "Quasi autem tenetur et voluptate possimus asperiores.", - "Quasi autem tenetur et voluptate possimus asperiores." + "Cum perspiciatis error quasi autem tenetur et." ] } ], "links": { - "OnFailure": "Pariatur itaque excepturi.", - "OnSuccess": "Rerum tempore velit consequatur consectetur." + "OnFailure": "Possimus asperiores ea pariatur.", + "OnSuccess": "Excepturi repellendus rerum tempore." } }`, RunE: func(cmd *cobra.Command, args []string) error { return tmp13.Run(c, args) }, @@ -777,12 +781,12 @@ Payload example: command.AddCommand(sub) app.AddCommand(command) command = &cobra.Command{ - Use: "generate", - Short: `Generate a set of Tokens for different Auth levels. NOT FOR PRODUCTION. Only available if server is running in dev mode`, + Use: "has-scope", + Short: `Checks if the user has the given scope on the requested resource`, } - tmp19 := new(GenerateTokenCommand) + tmp19 := new(HasScopeResourceRolesCommand) sub = &cobra.Command{ - Use: `token ["/api/token/generate"]`, + Use: `resource-roles ["/api/resources/RESOURCEID/scopes/SCOPENAME"]`, Short: ``, RunE: func(cmd *cobra.Command, args []string) error { return tmp19.Run(c, args) }, } @@ -791,12 +795,12 @@ Payload example: command.AddCommand(sub) app.AddCommand(command) command = &cobra.Command{ - Use: "has-scope", - Short: `Checks if the user has the given scope on the requested resource`, + Use: "keys", + Short: `Returns public keys which should be used to verify tokens`, } - tmp20 := new(HasScopeResourceRolesCommand) + tmp20 := new(KeysTokenCommand) sub = &cobra.Command{ - Use: `resource-roles ["/api/resources/RESOURCEID/scopes/SCOPENAME"]`, + Use: `token ["/api/token/keys"]`, Short: ``, RunE: func(cmd *cobra.Command, args []string) error { return tmp20.Run(c, args) }, } @@ -805,12 +809,12 @@ Payload example: command.AddCommand(sub) app.AddCommand(command) command = &cobra.Command{ - Use: "keys", - Short: `Returns public keys which should be used to verify tokens`, + Use: "link", + Short: `Get a redirect location which should be used to initiate account linking between the user account and an external resource provider such as GitHub`, } - tmp21 := new(KeysTokenCommand) + tmp21 := new(LinkTokenCommand) sub = &cobra.Command{ - Use: `token ["/api/token/keys"]`, + Use: `token ["/api/token/link"]`, Short: ``, RunE: func(cmd *cobra.Command, args []string) error { return tmp21.Run(c, args) }, } @@ -819,12 +823,12 @@ Payload example: command.AddCommand(sub) app.AddCommand(command) command = &cobra.Command{ - Use: "link", - Short: `Get a redirect location which should be used to initiate account linking between the user account and an external resource provider such as GitHub`, + Use: "link-callback", + Short: `Callback from an external oauth2 resource provider such as GitHub as part of user's account linking`, } - tmp22 := new(LinkTokenCommand) + tmp22 := new(LinkCallbackTokenCommand) sub = &cobra.Command{ - Use: `token ["/api/token/link"]`, + Use: `token ["/api/token/link/callback"]`, Short: ``, RunE: func(cmd *cobra.Command, args []string) error { return tmp22.Run(c, args) }, } @@ -1049,9 +1053,9 @@ Payload example: } ], "included": [ - "c3d4ab19-6e68-4681-a613-0cc5952e49be", - "c3d4ab19-6e68-4681-a613-0cc5952e49be", - "c3d4ab19-6e68-4681-a613-0cc5952e49be" + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6", + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6", + "01be9eaa-32fd-47d9-b7dc-caa14b78f3b6" ] }`, RunE: func(cmd *cobra.Command, args []string) error { return tmp37.Run(c, args) }, @@ -1763,6 +1767,34 @@ func (cmd *RescindInviteInvitationCommand) RegisterFlags(cc *cobra.Command, c *a cc.Flags().StringVar(&cmd.InviteTo, "inviteTo", inviteTo, `Unique identifier for the invitation to the organization, team, security group or resource`) } +// Run makes the HTTP request corresponding to the CallbackLoginCommand command. +func (cmd *CallbackLoginCommand) Run(c *auth.Client, args []string) error { + var path string + if len(args) > 0 { + path = args[0] + } else { + path = "/api/login/callback" + } + logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) + ctx := goa.WithLogger(context.Background(), logger) + resp, err := c.CallbackLogin(ctx, path, stringFlagVal("code", cmd.Code), stringFlagVal("state", cmd.State)) + if err != nil { + goa.LogError(ctx, "failed", "err", err) + return err + } + + goaclient.HandleResponse(c.Client, resp, cmd.PrettyPrint) + return nil +} + +// RegisterFlags registers the command flags with the command line. +func (cmd *CallbackLoginCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { + var code string + cc.Flags().StringVar(&cmd.Code, "code", code, `Authorization code`) + var state string + cc.Flags().StringVar(&cmd.State, "state", state, `state value`) +} + // Run makes the HTTP request corresponding to the LoginLoginCommand command. func (cmd *LoginLoginCommand) Run(c *auth.Client, args []string) error { var path string @@ -1803,7 +1835,7 @@ func (cmd *LogoutLogoutCommand) Run(c *auth.Client, args []string) error { } logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) ctx := goa.WithLogger(context.Background(), logger) - resp, err := c.LogoutLogout(ctx, path, stringFlagVal("redirect", cmd.Redirect)) + resp, err := c.LogoutLogout(ctx, path, stringFlagVal("redirect", cmd.Redirect), stringFlagVal("Referer", cmd.Referer)) if err != nil { goa.LogError(ctx, "failed", "err", err) return err @@ -1817,6 +1849,7 @@ func (cmd *LogoutLogoutCommand) Run(c *auth.Client, args []string) error { func (cmd *LogoutLogoutCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { var redirect string cc.Flags().StringVar(&cmd.Redirect, "redirect", redirect, `URL to be redirected to after successful logout. If not set then will redirect to the referrer instead.`) + cc.Flags().StringVar(&cmd.Referer, "Referer", "", ``) } // Run makes the HTTP request corresponding to the DeprovisionNamedusersCommand command. @@ -2428,6 +2461,34 @@ func (cmd *ExchangeTokenCommand) RegisterFlags(cc *cobra.Command, c *auth.Client cc.Flags().StringVar(&cmd.ContentType, "content", "", "Request content type override, e.g. 'application/x-www-form-urlencoded'") } +// Run makes the HTTP request corresponding to the LinkCallbackTokenCommand command. +func (cmd *LinkCallbackTokenCommand) Run(c *auth.Client, args []string) error { + var path string + if len(args) > 0 { + path = args[0] + } else { + path = "/api/token/link/callback" + } + logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) + ctx := goa.WithLogger(context.Background(), logger) + resp, err := c.LinkCallbackToken(ctx, path, cmd.Code, cmd.State) + if err != nil { + goa.LogError(ctx, "failed", "err", err) + return err + } + + goaclient.HandleResponse(c.Client, resp, cmd.PrettyPrint) + return nil +} + +// RegisterFlags registers the command flags with the command line. +func (cmd *LinkCallbackTokenCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { + var code string + cc.Flags().StringVar(&cmd.Code, "code", code, `Code provided by an external oauth2 resource provider`) + var state string + cc.Flags().StringVar(&cmd.State, "state", state, `State generated by the link request`) +} + // Run makes the HTTP request corresponding to the RetrieveTokenCommand command. func (cmd *RetrieveTokenCommand) Run(c *auth.Client, args []string) error { var path string @@ -2528,58 +2589,6 @@ func (cmd *AuditTokenCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { cc.Flags().StringVar(&cmd.ResourceID, "resource_id", resourceID, `Resource ID of a resource on which the user wishes to perform an operation`) } -// Run makes the HTTP request corresponding to the CallbackTokenCommand command. -func (cmd *CallbackTokenCommand) Run(c *auth.Client, args []string) error { - var path string - if len(args) > 0 { - path = args[0] - } else { - path = "/api/token/link/callback" - } - logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) - ctx := goa.WithLogger(context.Background(), logger) - resp, err := c.CallbackToken(ctx, path, cmd.Code, cmd.State) - if err != nil { - goa.LogError(ctx, "failed", "err", err) - return err - } - - goaclient.HandleResponse(c.Client, resp, cmd.PrettyPrint) - return nil -} - -// RegisterFlags registers the command flags with the command line. -func (cmd *CallbackTokenCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { - var code string - cc.Flags().StringVar(&cmd.Code, "code", code, `Code provided by an external oauth2 resource provider`) - var state string - cc.Flags().StringVar(&cmd.State, "state", state, `State generated by the link request`) -} - -// Run makes the HTTP request corresponding to the GenerateTokenCommand command. -func (cmd *GenerateTokenCommand) Run(c *auth.Client, args []string) error { - var path string - if len(args) > 0 { - path = args[0] - } else { - path = "/api/token/generate" - } - logger := goa.NewLogger(log.New(os.Stderr, "", log.LstdFlags)) - ctx := goa.WithLogger(context.Background(), logger) - resp, err := c.GenerateToken(ctx, path) - if err != nil { - goa.LogError(ctx, "failed", "err", err) - return err - } - - goaclient.HandleResponse(c.Client, resp, cmd.PrettyPrint) - return nil -} - -// RegisterFlags registers the command flags with the command line. -func (cmd *GenerateTokenCommand) RegisterFlags(cc *cobra.Command, c *auth.Client) { -} - // Run makes the HTTP request corresponding to the KeysTokenCommand command. func (cmd *KeysTokenCommand) Run(c *auth.Client, args []string) error { var path string