Skip to content

Commit 1132691

Browse files
committed
Rename Confidential field to ConfidentialClient
1 parent 918472d commit 1132691

File tree

15 files changed

+84
-84
lines changed

15 files changed

+84
-84
lines changed

models/auth/oauth2.go

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,10 @@ type OAuth2Application struct {
3535
// https://datatracker.ietf.org/doc/html/rfc6749#section-2.1
3636
// "Authorization servers MUST record the client type in the client registration details"
3737
// https://datatracker.ietf.org/doc/html/rfc8252#section-8.4
38-
Confidential bool `xorm:"NOT NULL DEFAULT TRUE"`
39-
RedirectURIs []string `xorm:"redirect_uris JSON TEXT"`
40-
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
41-
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
38+
ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"`
39+
RedirectURIs []string `xorm:"redirect_uris JSON TEXT"`
40+
CreatedUnix timeutil.TimeStamp `xorm:"INDEX created"`
41+
UpdatedUnix timeutil.TimeStamp `xorm:"INDEX updated"`
4242
}
4343

4444
func init() {
@@ -62,7 +62,7 @@ func (app *OAuth2Application) PrimaryRedirectURI() string {
6262

6363
// ContainsRedirectURI checks if redirectURI is allowed for app
6464
func (app *OAuth2Application) ContainsRedirectURI(redirectURI string) bool {
65-
if !app.Confidential {
65+
if !app.ConfidentialClient {
6666
uri, err := url.Parse(redirectURI)
6767
// ignore port for http loopback uris following https://datatracker.ietf.org/doc/html/rfc8252#section-7.3
6868
if err == nil && uri.Scheme == "http" && uri.Port() != "" {
@@ -168,21 +168,21 @@ func GetOAuth2ApplicationsByUserID(ctx context.Context, userID int64) (apps []*O
168168

169169
// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
170170
type CreateOAuth2ApplicationOptions struct {
171-
Name string
172-
UserID int64
173-
Confidential bool
174-
RedirectURIs []string
171+
Name string
172+
UserID int64
173+
ConfidentialClient bool
174+
RedirectURIs []string
175175
}
176176

177177
// CreateOAuth2Application inserts a new oauth2 application
178178
func CreateOAuth2Application(ctx context.Context, opts CreateOAuth2ApplicationOptions) (*OAuth2Application, error) {
179179
clientID := uuid.New().String()
180180
app := &OAuth2Application{
181-
UID: opts.UserID,
182-
Name: opts.Name,
183-
ClientID: clientID,
184-
RedirectURIs: opts.RedirectURIs,
185-
Confidential: opts.Confidential,
181+
UID: opts.UserID,
182+
Name: opts.Name,
183+
ClientID: clientID,
184+
RedirectURIs: opts.RedirectURIs,
185+
ConfidentialClient: opts.ConfidentialClient,
186186
}
187187
if err := db.Insert(ctx, app); err != nil {
188188
return nil, err
@@ -192,11 +192,11 @@ func CreateOAuth2Application(ctx context.Context, opts CreateOAuth2ApplicationOp
192192

193193
// UpdateOAuth2ApplicationOptions holds options to update an oauth2 application
194194
type UpdateOAuth2ApplicationOptions struct {
195-
ID int64
196-
Name string
197-
UserID int64
198-
Confidential bool
199-
RedirectURIs []string
195+
ID int64
196+
Name string
197+
UserID int64
198+
ConfidentialClient bool
199+
RedirectURIs []string
200200
}
201201

202202
// UpdateOAuth2Application updates an oauth2 application
@@ -217,7 +217,7 @@ func UpdateOAuth2Application(opts UpdateOAuth2ApplicationOptions) (*OAuth2Applic
217217

218218
app.Name = opts.Name
219219
app.RedirectURIs = opts.RedirectURIs
220-
app.Confidential = opts.Confidential
220+
app.ConfidentialClient = opts.ConfidentialClient
221221

222222
if err = updateOAuth2Application(ctx, app); err != nil {
223223
return nil, err
@@ -228,7 +228,7 @@ func UpdateOAuth2Application(opts UpdateOAuth2ApplicationOptions) (*OAuth2Applic
228228
}
229229

230230
func updateOAuth2Application(ctx context.Context, app *OAuth2Application) error {
231-
if _, err := db.GetEngine(ctx).ID(app.ID).UseBool("Confidential").Update(app); err != nil {
231+
if _, err := db.GetEngine(ctx).ID(app.ID).UseBool("ConfidentialClient").Update(app); err != nil {
232232
return err
233233
}
234234
return nil

models/auth/oauth2_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ func TestOAuth2Application_ContainsRedirectURI(t *testing.T) {
4545

4646
func TestOAuth2Application_ContainsRedirectURI_WithPort(t *testing.T) {
4747
app := &auth_model.OAuth2Application{
48-
RedirectURIs: []string{"http://127.0.0.1/", "http://::1/", "http://192.168.0.1/", "http://intranet/", "https://127.0.0.1/"},
49-
Confidential: false,
48+
RedirectURIs: []string{"http://127.0.0.1/", "http://::1/", "http://192.168.0.1/", "http://intranet/", "https://127.0.0.1/"},
49+
ConfidentialClient: false,
5050
}
5151

5252
// http loopback uris should ignore port

models/fixtures/oauth2_application.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
redirect_uris: '["a"]'
88
created_unix: 1546869730
99
updated_unix: 1546869730
10-
confidential: true
10+
confidential_client: true
1111
-
1212
id: 2
1313
uid: 2
@@ -17,4 +17,4 @@
1717
redirect_uris: '["http://127.0.0.1"]'
1818
created_unix: 1546869730
1919
updated_unix: 1546869730
20-
confidential: false
20+
confidential_client: false

models/migrations/migrations.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -416,7 +416,7 @@ var migrations = []Migration{
416416
// v226 -> v227
417417
NewMigration("Conan and generic packages do not need to be semantically versioned", fixPackageSemverField),
418418
// v227 -> v228
419-
NewMigration("Add confidential column default true to OAuth2Application table", addConfidentialColumnToOAuth2ApplicationTable),
419+
NewMigration("Add ConfidentialClient column (default true) to OAuth2Application table", addConfidentialClientColumnToOAuth2ApplicationTable),
420420
}
421421

422422
// GetCurrentDBVersion returns the current db version

models/migrations/v227.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ import (
88
"xorm.io/xorm"
99
)
1010

11-
// addConfidentialColumnToOAuth2ApplicationTable: add Confidential column, setting existing rows to true
12-
func addConfidentialColumnToOAuth2ApplicationTable(x *xorm.Engine) error {
11+
// addConfidentialColumnToOAuth2ApplicationTable: add ConfidentialClient column, setting existing rows to true
12+
func addConfidentialClientColumnToOAuth2ApplicationTable(x *xorm.Engine) error {
1313
type OAuth2Application struct {
14-
Confidential bool `xorm:"NOT NULL DEFAULT TRUE"`
14+
ConfidentialClient bool `xorm:"NOT NULL DEFAULT TRUE"`
1515
}
1616

1717
return x.Sync(new(OAuth2Application))

modules/convert/convert.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -392,13 +392,13 @@ func ToTopicResponse(topic *repo_model.Topic) *api.TopicResponse {
392392
// ToOAuth2Application convert from auth.OAuth2Application to api.OAuth2Application
393393
func ToOAuth2Application(app *auth.OAuth2Application) *api.OAuth2Application {
394394
return &api.OAuth2Application{
395-
ID: app.ID,
396-
Name: app.Name,
397-
ClientID: app.ClientID,
398-
ClientSecret: app.ClientSecret,
399-
Confidential: app.Confidential,
400-
RedirectURIs: app.RedirectURIs,
401-
Created: app.CreatedUnix.AsTime(),
395+
ID: app.ID,
396+
Name: app.Name,
397+
ClientID: app.ClientID,
398+
ClientSecret: app.ClientSecret,
399+
ConfidentialClient: app.ConfidentialClient,
400+
RedirectURIs: app.RedirectURIs,
401+
Created: app.CreatedUnix.AsTime(),
402402
}
403403
}
404404

modules/structs/user_app.go

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,21 +30,21 @@ type CreateAccessTokenOption struct {
3030

3131
// CreateOAuth2ApplicationOptions holds options to create an oauth2 application
3232
type CreateOAuth2ApplicationOptions struct {
33-
Name string `json:"name" binding:"Required"`
34-
Confidential bool `json:"confidential"`
35-
RedirectURIs []string `json:"redirect_uris" binding:"Required"`
33+
Name string `json:"name" binding:"Required"`
34+
ConfidentialClient bool `json:"confidential_client"`
35+
RedirectURIs []string `json:"redirect_uris" binding:"Required"`
3636
}
3737

3838
// OAuth2Application represents an OAuth2 application.
3939
// swagger:response OAuth2Application
4040
type OAuth2Application struct {
41-
ID int64 `json:"id"`
42-
Name string `json:"name"`
43-
ClientID string `json:"client_id"`
44-
ClientSecret string `json:"client_secret"`
45-
Confidential bool `json:"confidential"`
46-
RedirectURIs []string `json:"redirect_uris"`
47-
Created time.Time `json:"created"`
41+
ID int64 `json:"id"`
42+
Name string `json:"name"`
43+
ClientID string `json:"client_id"`
44+
ClientSecret string `json:"client_secret"`
45+
ConfidentialClient bool `json:"confidential_client"`
46+
RedirectURIs []string `json:"redirect_uris"`
47+
Created time.Time `json:"created"`
4848
}
4949

5050
// OAuth2ApplicationList represents a list of OAuth2 applications.

routers/api/v1/user/app.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -213,10 +213,10 @@ func CreateOauth2Application(ctx *context.APIContext) {
213213
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
214214

215215
app, err := auth_model.CreateOAuth2Application(ctx, auth_model.CreateOAuth2ApplicationOptions{
216-
Name: data.Name,
217-
UserID: ctx.Doer.ID,
218-
RedirectURIs: data.RedirectURIs,
219-
Confidential: data.Confidential,
216+
Name: data.Name,
217+
UserID: ctx.Doer.ID,
218+
RedirectURIs: data.RedirectURIs,
219+
ConfidentialClient: data.ConfidentialClient,
220220
})
221221
if err != nil {
222222
ctx.Error(http.StatusBadRequest, "", "error creating oauth2 application")
@@ -364,11 +364,11 @@ func UpdateOauth2Application(ctx *context.APIContext) {
364364
data := web.GetForm(ctx).(*api.CreateOAuth2ApplicationOptions)
365365

366366
app, err := auth_model.UpdateOAuth2Application(auth_model.UpdateOAuth2ApplicationOptions{
367-
Name: data.Name,
368-
UserID: ctx.Doer.ID,
369-
ID: appID,
370-
RedirectURIs: data.RedirectURIs,
371-
Confidential: data.Confidential,
367+
Name: data.Name,
368+
UserID: ctx.Doer.ID,
369+
ID: appID,
370+
RedirectURIs: data.RedirectURIs,
371+
ConfidentialClient: data.ConfidentialClient,
372372
})
373373
if err != nil {
374374
if auth_model.IsErrOauthClientIDInvalid(err) || auth_model.IsErrOAuthApplicationNotFound(err) {

routers/web/auth/oauth.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -432,7 +432,7 @@ func AuthorizeOAuth(ctx *context.Context) {
432432
case "":
433433
// "Authorization servers SHOULD reject authorization requests from native apps that don't use PKCE by returning an error message"
434434
// https://datatracker.ietf.org/doc/html/rfc8252#section-8.1
435-
if !app.Confidential {
435+
if !app.ConfidentialClient {
436436
// "the authorization endpoint MUST return the authorization error response with the "error" value set to "invalid_request""
437437
// https://datatracker.ietf.org/doc/html/rfc7636#section-4.4.1
438438
handleAuthorizeError(ctx, AuthorizeError{

routers/web/user/setting/oauth2_common.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,10 @@ func (oa *OAuth2CommonHandlers) AddApp(ctx *context.Context) {
3939

4040
// TODO validate redirect URI
4141
app, err := auth.CreateOAuth2Application(ctx, auth.CreateOAuth2ApplicationOptions{
42-
Name: form.Name,
43-
RedirectURIs: []string{form.RedirectURI},
44-
UserID: oa.OwnerID,
45-
Confidential: form.Confidential,
42+
Name: form.Name,
43+
RedirectURIs: []string{form.RedirectURI},
44+
UserID: oa.OwnerID,
45+
ConfidentialClient: form.ConfidentialClient,
4646
})
4747
if err != nil {
4848
ctx.ServerError("CreateOAuth2Application", err)
@@ -91,11 +91,11 @@ func (oa *OAuth2CommonHandlers) EditSave(ctx *context.Context) {
9191
// TODO validate redirect URI
9292
var err error
9393
if ctx.Data["App"], err = auth.UpdateOAuth2Application(auth.UpdateOAuth2ApplicationOptions{
94-
ID: ctx.ParamsInt64("id"),
95-
Name: form.Name,
96-
RedirectURIs: []string{form.RedirectURI},
97-
UserID: oa.OwnerID,
98-
Confidential: form.Confidential,
94+
ID: ctx.ParamsInt64("id"),
95+
Name: form.Name,
96+
RedirectURIs: []string{form.RedirectURI},
97+
UserID: oa.OwnerID,
98+
ConfidentialClient: form.ConfidentialClient,
9999
}); err != nil {
100100
ctx.ServerError("UpdateOAuth2Application", err)
101101
return

0 commit comments

Comments
 (0)