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

cmd: Add clients list command #1311

Merged
merged 2 commits into from
Mar 15, 2019
Merged

Conversation

sawadashota
Copy link
Contributor

@sawadashota sawadashota commented Mar 14, 2019

Related issue

#1310

Proposed changes

Add hydra clients list command.
In this PR, command renders columns only client_id, name, response type, scope, RedirectUris, GrantTypes, TokenEndpointAuthMethod.

The command behaves like following.

$ go run main.go clients list --help
This command list an OAuth 2.0 Clients.

Example:
  hydra clients list

Usage:
  hydra clients list [flags]

Flags:
  -h, --help        help for list
      --limit int   The maximum amount of policies returned. (default 20)
      --page int    The number of page. (default 1)

Global Flags:
      --access-token string    Set an access token to be used in the Authorization header, defaults to environment variable OAUTH2_ACCESS_TOKEN
      --endpoint string        Set the URL where ORY Hydra is hosted, defaults to environment variable HYDRA_ADMIN_URL
      --fake-tls-termination   Fake tls termination by adding "X-Forwarded-Proto: https" to http headers
      --skip-tls-verify        Foolishly accept TLS certificates signed by unkown certificate authorities

$ go run main.go clients list --endpoint 'http://localhost:4445'
|              CLIENT ID               |   NAME    | RESPONSE TYPES |        SCOPE         |         REDIRECT URIS         |    GRANT TYPES     | TOKEN ENDPOINT AUTH METHOD |
|--------------------------------------|-----------|----------------|----------------------|-------------------------------|--------------------|----------------------------|
| b56de81b-5851-41e3-85ba-092883b094b1 | example3  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| be7047ff-bf38-4041-8ed5-652d0190b97d | example4  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| decf2324-2236-48b1-b3df-c55c3787877b | example8  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 1a02a217-6b67-4e17-b58f-8da04ca9a3ca | example12 | id_token,code  | openid profile email | https://example.com/callback  | authorization_code | none                       |
|                                      |           |                |                      | https://example.com/callback2 |                    |                            |
| 644df9cc-3f96-4898-b051-0e46c2d15d5d | example   | id_token,code  | openid profile email | https://example.com/callback  | authorization_code | none                       |
| ff99c49a-32b4-4532-9e90-dc044074c95e | example2  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| f94bc770-e8fe-4b90-8df4-38459c202f43 | example5  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 4c6dc0cd-de22-44f7-b658-eb30e1740f37 | example6  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 1fd91b28-36dc-4619-baa2-98f34d8c9273 | example7  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 2f84958e-b00d-46bc-b68b-9596f8e311c5 | example9  | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 51528e84-bcad-429f-9a22-561d53f7c1f2 | example10 | token          | hoge                 |                               | client_credentials | client_secret_basic        |
| 401fd0ab-89fd-41c7-bff4-6c58d79cf724 | example11 | token          | hoge                 |                               | client_credentials | client_secret_basic        |

$ go run main.go clients list --endpoint 'http://localhost:4445' --limit 2 --page 1
|              CLIENT ID               |   NAME   | RESPONSE TYPES |        SCOPE         |        REDIRECT URIS         |    GRANT TYPES     | TOKEN ENDPOINT AUTH METHOD |
|--------------------------------------|----------|----------------|----------------------|------------------------------|--------------------|----------------------------|
| 644df9cc-3f96-4898-b051-0e46c2d15d5d | example  | id_token,code  | openid profile email | https://example.com/callback | authorization_code | none                       |
| ff99c49a-32b4-4532-9e90-dc044074c95e | example2 | token          | hoge                 |                              | client_credentials | client_secret_basic        |

$ go run main.go clients list --endpoint 'http://localhost:4445' --limit 2 --page 2
|              CLIENT ID               |   NAME   | RESPONSE TYPES | SCOPE | REDIRECT URIS |    GRANT TYPES     | TOKEN ENDPOINT AUTH METHOD |
|--------------------------------------|----------|----------------|-------|---------------|--------------------|----------------------------|
| b56de81b-5851-41e3-85ba-092883b094b1 | example3 | token          | hoge  |               | client_credentials | client_secret_basic        |
| be7047ff-bf38-4041-8ed5-652d0190b97d | example4 | token          | hoge  |               | client_credentials | client_secret_basic        |

Checklist

  • I have read the contributing guidelines
  • I confirm that this pull request does not address a security vulnerability. If this pull request addresses a security
    vulnerability, I confirm that I got green light (please contact hi@ory.sh) from the maintainers to push the changes.
  • I signed the Developer's Certificate of Origin
    by signing my commit(s). You can amend your signature to the most recent commit by using git commit --amend -s. If you
    amend the commit, you might need to force push using git push --force HEAD:<branch>. Please be very careful when using
    force push.
  • I have added tests that prove my fix is effective or that my feature works
  • I have added necessary documentation within the code base (if appropriate)
  • I have documented my changes in the developer guide (if appropriate)

Further comments

To render table, added following package.
https://github.com/olekukonko/tablewriter

Copy link
Member

@aeneasr aeneasr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome changes! Just some nitpicks, then this can get merged!

@@ -148,3 +148,25 @@ func (h *ClientHandler) GetClient(cmd *cobra.Command, args []string) {
checkResponse(err, http.StatusOK, response)
fmt.Println(cmdx.FormatResponse(&cl))
}

func (h *ClientHandler) ListClient(cmd *cobra.Command, args []string) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's rename this to ListClients :)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops... I fixed!

checkResponse(err, http.StatusOK, response)

table := newTable()
table.SetHeader([]string{"Client ID", "Name", "Response Type", "Scope"})
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Response Type should be Response Types. I also think it would be important to add the following fields:

  • RedirectUris
  • GrantTypes
  • TokenEndpointAuthMethod

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Exactly! Have added :)

Signed-off-by: Shota SAWADA <xiootas@gmail.com>
… TokenEndpointAuthMethod

Signed-off-by: Shota SAWADA <xiootas@gmail.com>
@sawadashota sawadashota force-pushed the cmd/add-clients-list branch from 1aa9d12 to ff8145d Compare March 14, 2019 15:33
@aeneasr
Copy link
Member

aeneasr commented Mar 15, 2019

Awesome, thank you!

@aeneasr aeneasr merged commit 21a14a1 into ory:master Mar 15, 2019
@sawadashota sawadashota deleted the cmd/add-clients-list branch March 15, 2019 13:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants