Skip to content

Add api support for external authentication management #34234

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

Open
wants to merge 19 commits into
base: main
Choose a base branch
from

Conversation

uvulpos
Copy link

@uvulpos uvulpos commented Apr 18, 2025

Summary:

As a DevOps Engineer, I want an automatic infrastructure setup with terraform and therefor have to enhance the gitea external api.

API:

+ GET - /api/v1/admin/identity-auth/oauth/
+ PUT - /api/v1/admin/identity-auth/oauth/
+ PATCH - /api/v1/admin/identity-auth/oauth/{id}
+ DELETE - /api/v1/admin/identity-auth/oauth/{id}

Terraform (later):

resource "gitea_login_source_provider" "oauth_authentik" {
  Name: "Authentik"
  Icon: "..."

  ConfigUrl = "..."
  ClientID = "..."
  ClientSecret = "..."
}

Todos:

  • Implement api endpoints
    • Get - Return Login Sources<
    • Put - Create an Oauth2 Source
    • Patch - Update an Oauth2 Source
    • Delete - Remove Oauth2 Source
    • Document API Endpoints inside Swagger
    • PR Feedback
      • Get Configuration by ID
      • Filter OAuth Configurations for type Oauth
      • Implement General Get Auth List for all kind of authentications
      • copyright date in new files should be from this year and I don't think gogs attribution here is needed(?)
      • comments in services/convert/auth_oauth.go don't match the functions
      • Remove Type ID from OAuth Return Struct

Other:

This is my first contribution to gitea so any help is appreciated

@GiteaBot GiteaBot added the lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. label Apr 18, 2025
@github-actions github-actions bot added modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code labels Apr 18, 2025
@uvulpos uvulpos marked this pull request as ready for review April 20, 2025 02:13
Comment on lines +1664 to +1665
m.Patch("/{id}", bind(api.EditAuthOauth2Option{}), admin.EditOauthAuth)
m.Delete("/{id}", admin.DeleteOauthAuth)
Copy link
Author

Choose a reason for hiding this comment

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

parameter via url or url param?

Copy link
Contributor

Choose a reason for hiding this comment

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

Unless someone else has different opinion I think it should stay like this.
What about getting the current configuration for an ID?

Copy link
Author

@uvulpos uvulpos Apr 20, 2025

Choose a reason for hiding this comment

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

But what's the current configuration? We can have n login sources configured and you can access it via pat so no auth source is getting used at all

Ok, I'll add this feature to get a config by ID


listOptions := utils.GetListOptions(ctx)

authSources, maxResults, err := db.FindAndCount[auth_model.Source](ctx, auth_model.FindSourcesOptions{})
Copy link
Author

@uvulpos uvulpos Apr 20, 2025

Choose a reason for hiding this comment

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

Filter and return just type OAuth
[Help appreciated]

Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure search is needed? Second opinion would be nice this though.

Copy link
Author

Choose a reason for hiding this comment

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

The url explicit says oauth, so I'm not sure if I want to receive LDAP connections

Copy link
Contributor

Choose a reason for hiding this comment

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

To filter for oauth only you should add LoginType: auth_model.OAuth2 to the struct.

But I was wondering why oauth search specifically instead of more generic one? The struct doesn't really let you filter by much more too.

Copy link
Contributor

@TheFox0x7 TheFox0x7 left a comment

Choose a reason for hiding this comment

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

I haven't tested the changes yet or looked too deep into it, at a glance it looks like it's a good starting point.
In case you haven't yet seen it: https://github.com/go-gitea/gitea/blob/main/cmd/admin_auth_oauth.go covers cli endpoint for adding oauth, which you might find useful.

Few minor points:

  • copyright date in new files should be from this year and I don't think gogs attribution here is needed(?)
  • comments in services/convert/auth_oauth.go don't match the functions

Comment on lines 10 to 11
Type int `json:"type"`
TypeName string `json:"type_name"`
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure why end user would be interested in numeric type?

Copy link
Author

@uvulpos uvulpos Apr 20, 2025

Choose a reason for hiding this comment

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

I was not sure, but I think it's more unique than the name for machine readability. But... I don't know. Opinions are welcome :)

Comment on lines +1664 to +1665
m.Patch("/{id}", bind(api.EditAuthOauth2Option{}), admin.EditOauthAuth)
m.Delete("/{id}", admin.DeleteOauthAuth)
Copy link
Contributor

Choose a reason for hiding this comment

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

Unless someone else has different opinion I think it should stay like this.
What about getting the current configuration for an ID?


listOptions := utils.GetListOptions(ctx)

authSources, maxResults, err := db.FindAndCount[auth_model.Source](ctx, auth_model.FindSourcesOptions{})
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm not sure search is needed? Second opinion would be nice this though.

@lunny lunny added this to the 1.25.0 milestone Apr 21, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lgtm/need 2 This PR needs two approvals by maintainers to be considered for merging. modifies/api This PR adds API routes or modifies them modifies/go Pull requests that update Go code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants