Skip to content

Commit c830bc1

Browse files
committed
Refactor AuthOauth2Option structure and improve error handling in CreateOauthAuth
1 parent c2f5544 commit c830bc1

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

modules/structs/auth_oauth2.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,13 @@
55
package structs
66

77
type AuthOauth2Option struct {
8-
SourceID int64 `json:"source_id"`
8+
ID int64 `json:"id"`
99
AuthenticationName string `json:"authentication_name" binding:"Required"`
10-
ProviderIconURL string `json:"provider_icon_url"`
10+
Type int `json:"type"`
11+
TypeName string `json:"type_name"`
12+
13+
IsActive bool `json:"is_active"`
14+
IsSyncEnabled bool `json:"is_sync_enabled"`
1115
}
1216

1317
// CreateUserOption create user options

routers/api/v1/admin/auth_oauth.go

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,8 @@ func CreateOauthAuth(ctx *context.APIContext) {
3535

3636
discoveryURL, err := url.Parse(form.ProviderAutoDiscoveryURL)
3737
if err != nil || (discoveryURL.Scheme != "http" && discoveryURL.Scheme != "https") {
38-
fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL)
39-
40-
// todo: implement handling
38+
_ = fmt.Errorf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL)
39+
ctx.HTTPError(http.StatusBadRequest, fmt.Sprintf("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)", form.ProviderAutoDiscoveryURL))
4140
}
4241

4342
config := &oauth2.Source{
@@ -67,8 +66,6 @@ func CreateOauthAuth(ctx *context.APIContext) {
6766
})
6867

6968
ctx.Status(http.StatusCreated)
70-
71-
// ctx.JSON(http.StatusCreated, convert.ToUser(ctx, u, ctx.Doer))
7269
}
7370

7471
// EditOauthAuth api for modifying a authentication method

services/convert/auth_oauth.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,12 @@ func ToOauthProviders(ctx context.Context, provider []*auth_model.Source) []*api
3131

3232
func toOauthProvider(ctx context.Context, provider *auth_model.Source) *api.AuthOauth2Option {
3333
return &api.AuthOauth2Option{
34-
SourceID: provider.ID,
34+
ID: provider.ID,
3535
AuthenticationName: provider.Name,
36+
Type: provider.Type.Int(),
37+
TypeName: provider.Type.String(),
38+
39+
IsActive: provider.IsActive,
40+
IsSyncEnabled: provider.IsSyncEnabled,
3641
}
3742
}

0 commit comments

Comments
 (0)