forgejo/cmd
joneshf d4873965c8 feat: add --attribute-ssh-pubic-key to forgejo admin auth add-oauth and update-oauth CLI (#8383)
As explained in https://codeberg.org/forgejo/forgejo/issues/8072, the CLI was missing a way to set the `AttributeSSHPublicKey` field that was added in https://codeberg.org/forgejo/forgejo/pulls/6232. We add a flag to do that, and thread it through where necessary.

The checklist mentions adding tests, but the code in `cmd/admin_auth_oauth.go` seems to not have a `cmd/admin_auth_oauth_test.go`, and I'm not sure if there's something else that's testing this behavior. I can try to add tests if there's already a good spot to slot them in. If not, it seems like adding a `cmd/cmd/admin_auth_oauth_test.go` that worked similar to the current `cmd/admin_auth_ldap_test.go` might be a bit big of a change.

As far as documentation, I might be wrong about this, but it seems like the CLI docs are only updated once there's a new release. I can't do that yet, so I don't think that either of the checkboxes apply to this PR.

## Manual testing

There are two CLI commands that can be validated: `forgejo admin auth add-oauth` and `forgejo admin auth update-oauth`.
1. `forgejo admin auth add-oauth` requires an actual auto-discovery URL that responds appropriately.

    - If there is not already an OIDC provider set up that has an auto-discovery URL, the sample OIDC provider at https://openidconnect.net/ can be used with it's auto-discovery URL of https://samples.auth0.com/.well-known/openid-configuration.

1. Run the following command to create a new OAuth2 authentication source:
    ```Console
    forgejo admin auth add-oauth --attribute-ssh-public-key=ssh_public_key_field --auto-discover-url=https://samples.auth0.com/.well-known/openid-configuration --name='Delete this later' --provider=openidConnect
    ```

    - This should create a new OAuth2 authentication source named "Delete this later" with the "Public SSH key attribute" field set to `ssh_public_key_field`.
        <details>
        <summary>Screenshot of newly created OAuth2 authentication source</summary>

        ![forgejo-admin-auth-add-oauth](/attachments/166f3f82-adc8-4ef9-9128-fb8a923fdc0d)
        </details>

1. `forgejo admin auth update-oauth` requires the id of the newly created OAuth2 authentication source.

    - This id can be found on either the "Authentication sources" page (`/admin/auths`) or as the URL of the newly created OAuth2 authentication source (`/admins/auths/{id}`).

1. Run the following command to update the OAuth2 authentication source:
    ```Console
    forgejo admin auth update-oauth --attribute-ssh-public-key=ssh_public_key_field_new_name --id=<id-of-new-oauth2-authentication-source>
    ```

    - This should change the "Public SSH key attribute" to `ssh_public_key_field_new_name`.

        <details>
        <summary>Screenshot of updated OAuth2 authentication source</summary>

        ![forgejo-admin-auth-update-oauth](/attachments/9674dba0-6ed1-4fb8-8eb8-d7f33cbf8c3a)
        </details>

## Checklist

The [contributor guide](https://forgejo.org/docs/next/contributor/) contains information that will be helpful to first time contributors. There also are a few [conditions for merging Pull Requests in Forgejo repositories](https://codeberg.org/forgejo/governance/src/branch/main/PullRequestsAgreement.md). You are also welcome to join the [Forgejo development chatroom](https://matrix.to/#/#forgejo-development:matrix.org).

### Tests

- I added test coverage for Go changes...
  - [ ] in their respective `*_test.go` for unit tests.
  - [ ] in the `tests/integration` directory if it involves interactions with a live Forgejo server.
- I added test coverage for JavaScript changes...
  - [ ] in `web_src/js/*.test.js` if it can be unit tested.
  - [ ] in `tests/e2e/*.test.e2e.js` if it requires interactions with a live Forgejo server (see also the [developer guide for JavaScript testing](https://codeberg.org/forgejo/forgejo/src/branch/forgejo/tests/e2e/README.md#end-to-end-tests)).

### Documentation

- [ ] I created a pull request [to the documentation](https://codeberg.org/forgejo/docs) to explain to Forgejo users how to use this change.
- [ ] I did not document these changes and I do not expect someone else to do it.

### Release notes

- [ ] I do not want this change to show in the release notes.
- [x] I want the title to show in the release notes with a link to this pull request.
- [ ] I want the content of the `release-notes/<pull request number>.md` to be be used for the release notes instead of the title.

<!--start release-notes-assistant-->

## Release notes
<!--URL:https://codeberg.org/forgejo/forgejo-->
- Features
  - [PR](https://codeberg.org/forgejo/forgejo/pulls/8383): <!--number 8383 --><!--line 0 --><!--description YWRkIGAtLWF0dHJpYnV0ZS1zc2gtcHViaWMta2V5YCB0byBmb3JnZWpvIGFkbWluIGF1dGggYWRkLW9hdXRoIGFuZCB1cGRhdGUtb2F1dGggQ0xJ-->add `--attribute-ssh-pubic-key` to forgejo admin auth add-oauth and update-oauth CLI<!--description-->
<!--end release-notes-assistant-->

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/8383
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Co-authored-by: joneshf <jones3.hardy@gmail.com>
Co-committed-by: joneshf <jones3.hardy@gmail.com>
2025-07-05 13:53:00 +02:00
..
forgejo chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
actions.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_auth.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_auth_ldap.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_auth_ldap_test.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_auth_oauth.go feat: add --attribute-ssh-pubic-key to forgejo admin auth add-oauth and update-oauth CLI (#8383) 2025-07-05 13:53:00 +02:00
admin_auth_stmp.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_regenerate.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user.go feat: add admin user reset-mfa CLI command (#8047) 2025-06-05 10:40:21 +02:00
admin_user_change_password.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_create.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_delete.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_generate_access_token.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_list.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_must_change_password.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
admin_user_reset_mfa.go feat: add admin user reset-mfa CLI command (#8047) 2025-06-05 10:40:21 +02:00
cert.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
cmd.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
doctor.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
doctor_convert.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
doctor_test.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
dump.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
dump_repo.go [gitea] week 2025-19 cherry pick (gitea/main -> forgejo) (#7909) 2025-06-27 13:59:07 +02:00
dump_test.go Add testifylint to lint checks (#4535) 2024-07-30 19:41:10 +00:00
embedded.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
generate.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
hook.go feat: bump the minimum required Git version from 2.0.0 to 2.34.1 (#8328) 2025-06-29 00:44:18 +02:00
hook_test.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
keys.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
mailer.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
main.go fix: CLI is forgejo not Forgejo (#8049) 2025-06-03 09:25:58 +02:00
main_test.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
manager.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
manager_logging.go feat: add a EXCLUSION to the logger (#8212) 2025-07-04 00:08:23 +02:00
migrate.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
migrate_storage.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
migrate_storage_test.go Update module github.com/golangci/golangci-lint/cmd/golangci-lint to v2 (forgejo) (#7367) 2025-03-28 22:22:21 +00:00
restore_repo.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
serv.go feat: bump the minimum required Git version from 2.0.0 to 2.34.1 (#8328) 2025-06-29 00:44:18 +02:00
web.go chore(upgrade): urfave/cli from v2 to v3 (#8035) 2025-06-01 22:16:37 +02:00
web_acme.go fix acme renewal (#7409) 2025-04-06 15:26:47 +00:00
web_graceful.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00
web_https.go chore: branding import path (#7337) 2025-03-27 19:40:14 +00:00