mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-20 19:08:29 +02:00
Refactor OAuth authentication methods for improved error handling and code clarity
This commit is contained in:
parent
4787ea4bbf
commit
cb0e0cef86
@ -58,13 +58,18 @@ func CreateOauthAuth(ctx *context.APIContext) {
|
|||||||
GroupTeamMapRemoval: form.RemoveUsersFromSyncronizedTeams,
|
GroupTeamMapRemoval: form.RemoveUsersFromSyncronizedTeams,
|
||||||
}
|
}
|
||||||
|
|
||||||
auth_model.CreateSource(ctx, &auth_model.Source{
|
createErr := auth_model.CreateSource(ctx, &auth_model.Source{
|
||||||
Type: auth_model.OAuth2,
|
Type: auth_model.OAuth2,
|
||||||
Name: form.AuthenticationName,
|
Name: form.AuthenticationName,
|
||||||
IsActive: true,
|
IsActive: true,
|
||||||
Cfg: config,
|
Cfg: config,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
if createErr != nil {
|
||||||
|
ctx.APIErrorInternal(createErr)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
ctx.Status(http.StatusCreated)
|
ctx.Status(http.StatusCreated)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -74,14 +79,13 @@ func EditOauthAuth(ctx *context.APIContext) {
|
|||||||
|
|
||||||
// DeleteOauthAuth api for deleting a authentication method
|
// DeleteOauthAuth api for deleting a authentication method
|
||||||
func DeleteOauthAuth(ctx *context.APIContext) {
|
func DeleteOauthAuth(ctx *context.APIContext) {
|
||||||
oauthIdString := ctx.PathParam("id")
|
oauthIDString := ctx.PathParam("id")
|
||||||
oauthID, oauthIdErr := strconv.Atoi(oauthIdString)
|
oauthID, oauthIDErr := strconv.Atoi(oauthIDString)
|
||||||
if oauthIdErr != nil {
|
if oauthIDErr != nil {
|
||||||
ctx.APIErrorInternal(oauthIdErr)
|
ctx.APIErrorInternal(oauthIDErr)
|
||||||
}
|
}
|
||||||
|
|
||||||
err := auth_model.DeleteSource(ctx, int64(oauthID))
|
err := auth_model.DeleteSource(ctx, int64(oauthID))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.APIErrorInternal(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
@ -95,8 +99,6 @@ func SearchOauthAuth(ctx *context.APIContext) {
|
|||||||
listOptions := utils.GetListOptions(ctx)
|
listOptions := utils.GetListOptions(ctx)
|
||||||
|
|
||||||
authSources, maxResults, err := db.FindAndCount[auth_model.Source](ctx, auth_model.FindSourcesOptions{})
|
authSources, maxResults, err := db.FindAndCount[auth_model.Source](ctx, auth_model.FindSourcesOptions{})
|
||||||
// fmt.Printf("Count: %d, models: %v, err: %v", count, models[0].Name, err)
|
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
ctx.APIErrorInternal(err)
|
ctx.APIErrorInternal(err)
|
||||||
return
|
return
|
||||||
|
@ -17,7 +17,7 @@ func ToOauthProvider(ctx context.Context, provider *auth_model.Source) *api.Auth
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
return toOauthProvider(ctx, provider)
|
return toOauthProvider(provider)
|
||||||
}
|
}
|
||||||
|
|
||||||
// ToUsers convert list of user_model.User to list of api.User
|
// ToUsers convert list of user_model.User to list of api.User
|
||||||
@ -29,7 +29,7 @@ func ToOauthProviders(ctx context.Context, provider []*auth_model.Source) []*api
|
|||||||
return result
|
return result
|
||||||
}
|
}
|
||||||
|
|
||||||
func toOauthProvider(ctx context.Context, provider *auth_model.Source) *api.AuthOauth2Option {
|
func toOauthProvider(provider *auth_model.Source) *api.AuthOauth2Option {
|
||||||
return &api.AuthOauth2Option{
|
return &api.AuthOauth2Option{
|
||||||
ID: provider.ID,
|
ID: provider.ID,
|
||||||
AuthenticationName: provider.Name,
|
AuthenticationName: provider.Name,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user