mirror of
https://github.com/go-gitea/gitea.git
synced 2025-07-19 08:30:49 +02:00
Refactor AuthOauth2Option structure and improve error handling in CreateOauthAuth
This commit is contained in:
parent
c2f5544d73
commit
c830bc13e4
@ -5,9 +5,13 @@
|
|||||||
package structs
|
package structs
|
||||||
|
|
||||||
type AuthOauth2Option struct {
|
type AuthOauth2Option struct {
|
||||||
SourceID int64 `json:"source_id"`
|
ID int64 `json:"id"`
|
||||||
AuthenticationName string `json:"authentication_name" binding:"Required"`
|
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
|
// CreateUserOption create user options
|
||||||
|
@ -35,9 +35,8 @@ func CreateOauthAuth(ctx *context.APIContext) {
|
|||||||
|
|
||||||
discoveryURL, err := url.Parse(form.ProviderAutoDiscoveryURL)
|
discoveryURL, err := url.Parse(form.ProviderAutoDiscoveryURL)
|
||||||
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
|
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)
|
_ = 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))
|
||||||
// todo: implement handling
|
|
||||||
}
|
}
|
||||||
|
|
||||||
config := &oauth2.Source{
|
config := &oauth2.Source{
|
||||||
@ -67,8 +66,6 @@ func CreateOauthAuth(ctx *context.APIContext) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
ctx.Status(http.StatusCreated)
|
ctx.Status(http.StatusCreated)
|
||||||
|
|
||||||
// ctx.JSON(http.StatusCreated, convert.ToUser(ctx, u, ctx.Doer))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// EditOauthAuth api for modifying a authentication method
|
// EditOauthAuth api for modifying a authentication method
|
||||||
|
@ -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 {
|
func toOauthProvider(ctx context.Context, provider *auth_model.Source) *api.AuthOauth2Option {
|
||||||
return &api.AuthOauth2Option{
|
return &api.AuthOauth2Option{
|
||||||
SourceID: provider.ID,
|
ID: provider.ID,
|
||||||
AuthenticationName: provider.Name,
|
AuthenticationName: provider.Name,
|
||||||
|
Type: provider.Type.Int(),
|
||||||
|
TypeName: provider.Type.String(),
|
||||||
|
|
||||||
|
IsActive: provider.IsActive,
|
||||||
|
IsSyncEnabled: provider.IsSyncEnabled,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user