@@ -24,15 +24,6 @@ import (
2424func CreateOauthAuth (ctx * context.APIContext ) {
2525 form := web .GetForm (ctx ).(* api.CreateAuthOauth2Option )
2626
27- // ??? todo: what should I do here?
28- var scopes []string
29- // for _, s := range strings.Split(form.Oauth2Scopes, ",") {
30- // s = strings.TrimSpace(s)
31- // if s != "" {
32- // scopes = append(scopes, s)
33- // }
34- // }
35-
3627 discoveryURL , err := url .Parse (form .ProviderAutoDiscoveryURL )
3728 if err != nil || (discoveryURL .Scheme != "http" && discoveryURL .Scheme != "https" ) {
3829 _ = fmt .Errorf ("invalid Auto Discovery URL: %s (this must be a valid URL starting with http:// or https://)" , form .ProviderAutoDiscoveryURL )
@@ -46,7 +37,7 @@ func CreateOauthAuth(ctx *context.APIContext) {
4637 OpenIDConnectAutoDiscoveryURL : form .ProviderAutoDiscoveryURL ,
4738 CustomURLMapping : nil ,
4839 IconURL : form .ProviderIconURL ,
49- Scopes : scopes ,
40+ Scopes : generateScopes () ,
5041 RequiredClaimName : form .RequiredClaimName ,
5142 RequiredClaimValue : form .RequiredClaimValue ,
5243 SkipLocalTwoFA : form .SkipLocal2FA ,
@@ -75,6 +66,47 @@ func CreateOauthAuth(ctx *context.APIContext) {
7566
7667// EditOauthAuth api for modifying a authentication method
7768func EditOauthAuth (ctx * context.APIContext ) {
69+ oauthIDString := ctx .PathParam ("id" )
70+ oauthID , oauthIDErr := strconv .Atoi (oauthIDString )
71+ if oauthIDErr != nil {
72+ ctx .APIErrorInternal (oauthIDErr )
73+ }
74+
75+ form := web .GetForm (ctx ).(* api.CreateAuthOauth2Option )
76+
77+ config := & oauth2.Source {
78+ Provider : "openidConnect" ,
79+ ClientID : form .ProviderClientID ,
80+ ClientSecret : form .ProviderClientSecret ,
81+ OpenIDConnectAutoDiscoveryURL : form .ProviderAutoDiscoveryURL ,
82+ CustomURLMapping : nil ,
83+ IconURL : form .ProviderIconURL ,
84+ Scopes : generateScopes (),
85+ RequiredClaimName : form .RequiredClaimName ,
86+ RequiredClaimValue : form .RequiredClaimValue ,
87+ SkipLocalTwoFA : form .SkipLocal2FA ,
88+
89+ GroupClaimName : form .ClaimNameProvidingGroupNameForSource ,
90+ RestrictedGroup : form .GroupClaimValueForRestrictedUsers ,
91+ AdminGroup : form .GroupClaimValueForAdministratorUsers ,
92+ GroupTeamMap : form .MapClaimedGroupsToOrganizationTeams ,
93+ GroupTeamMapRemoval : form .RemoveUsersFromSyncronizedTeams ,
94+ }
95+
96+ updateErr := auth_model .UpdateSource (ctx , & auth_model.Source {
97+ ID : int64 (oauthID ),
98+ Type : auth_model .OAuth2 ,
99+ Name : form .AuthenticationName ,
100+ IsActive : true ,
101+ Cfg : config ,
102+ })
103+
104+ if updateErr != nil {
105+ ctx .APIErrorInternal (updateErr )
106+ return
107+ }
108+
109+ ctx .Status (http .StatusCreated )
78110}
79111
80112// DeleteOauthAuth api for deleting a authentication method
@@ -85,6 +117,17 @@ func DeleteOauthAuth(ctx *context.APIContext) {
85117 ctx .APIErrorInternal (oauthIDErr )
86118 }
87119
120+ source , sourceErr := auth_model .GetSourceByID (ctx , int64 (oauthID ))
121+ if sourceErr != nil {
122+ ctx .APIErrorInternal (sourceErr )
123+ return
124+ }
125+
126+ if source .Type != auth_model .OAuth2 {
127+ ctx .APIErrorNotFound ()
128+ return
129+ }
130+
88131 err := auth_model .DeleteSource (ctx , int64 (oauthID ))
89132 if err != nil {
90133 ctx .APIErrorInternal (err )
@@ -113,3 +156,17 @@ func SearchOauthAuth(ctx *context.APIContext) {
113156 ctx .SetTotalCountHeader (maxResults )
114157 ctx .JSON (http .StatusOK , & results )
115158}
159+
160+ // ??? todo: what should I do here?
161+ func generateScopes () []string {
162+ var scopes []string
163+
164+ // for _, s := range strings.Split(form.Oauth2Scopes, ",") {
165+ // s = strings.TrimSpace(s)
166+ // if s != "" {
167+ // scopes = append(scopes, s)
168+ // }
169+ // }
170+
171+ return scopes
172+ }
0 commit comments