0
0
mirror of https://github.com/go-gitea/gitea.git synced 2025-07-18 21:42:56 +02:00

Refactor AuthOauth2Option structure and improve error handling in CreateOauthAuth

This commit is contained in:
Tim Riedl 2025-04-19 00:01:37 +02:00
parent c2f5544d73
commit c830bc13e4
No known key found for this signature in database
GPG Key ID: 172D6410FC4F844E
3 changed files with 14 additions and 8 deletions

View File

@ -5,9 +5,13 @@
package structs
type AuthOauth2Option struct {
SourceID int64 `json:"source_id"`
ID int64 `json:"id"`
AuthenticationName string `json:"authentication_name" binding:"Required"`
ProviderIconURL string `json:"provider_icon_url"`
Type int `json:"type"`
TypeName string `json:"type_name"`
IsActive bool `json:"is_active"`
IsSyncEnabled bool `json:"is_sync_enabled"`
}
// CreateUserOption create user options

View File

@ -35,9 +35,8 @@ func CreateOauthAuth(ctx *context.APIContext) {
discoveryURL, err := url.Parse(form.ProviderAutoDiscoveryURL)
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL)
// todo: implement handling
_ = fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL)
ctx.HTTPError(http.StatusBadRequest, fmt.Sprintf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL))
}
config := &oauth2.Source{
@ -67,8 +66,6 @@ func CreateOauthAuth(ctx *context.APIContext) {
})
ctx.Status(http.StatusCreated)
// ctx.JSON(http.StatusCreated, convert.ToUser(ctx, u, ctx.Doer))
}
// EditOauthAuth api for modifying a authentication method

View File

@ -31,7 +31,12 @@ func ToOauthProviders(ctx context.Context, provider []*auth_model.Source) []*api
func toOauthProvider(ctx context.Context, provider *auth_model.Source) *api.AuthOauth2Option {
return &api.AuthOauth2Option{
SourceID: provider.ID,
ID: provider.ID,
AuthenticationName: provider.Name,
Type: provider.Type.Int(),
TypeName: provider.Type.String(),
IsActive: provider.IsActive,
IsSyncEnabled: provider.IsSyncEnabled,
}
}