@@ -14,8 +14,10 @@ import (
14
14
"text/tabwriter"
15
15
16
16
"code.gitea.io/gitea/models"
17
+ asymkey_model "code.gitea.io/gitea/models/asymkey"
17
18
"code.gitea.io/gitea/models/db"
18
19
"code.gitea.io/gitea/models/login"
20
+ user_model "code.gitea.io/gitea/models/user"
19
21
"code.gitea.io/gitea/modules/git"
20
22
"code.gitea.io/gitea/modules/graceful"
21
23
"code.gitea.io/gitea/modules/log"
@@ -297,6 +299,36 @@ var (
297
299
Name : "skip-local-2fa" ,
298
300
Usage : "Set to true to skip local 2fa for users authenticated by this source" ,
299
301
},
302
+ cli.StringSliceFlag {
303
+ Name : "scopes" ,
304
+ Value : nil ,
305
+ Usage : "Scopes to request when to authenticate against this OAuth2 source" ,
306
+ },
307
+ cli.StringFlag {
308
+ Name : "required-claim-name" ,
309
+ Value : "" ,
310
+ Usage : "Claim name that has to be set to allow users to login with this source" ,
311
+ },
312
+ cli.StringFlag {
313
+ Name : "required-claim-value" ,
314
+ Value : "" ,
315
+ Usage : "Claim value that has to be set to allow users to login with this source" ,
316
+ },
317
+ cli.StringFlag {
318
+ Name : "group-claim-name" ,
319
+ Value : "" ,
320
+ Usage : "Claim name providing group names for this source" ,
321
+ },
322
+ cli.StringFlag {
323
+ Name : "admin-group" ,
324
+ Value : "" ,
325
+ Usage : "Group Claim value for administrator users" ,
326
+ },
327
+ cli.StringFlag {
328
+ Name : "restricted-group" ,
329
+ Value : "" ,
330
+ Usage : "Group Claim value for restricted users" ,
331
+ },
300
332
}
301
333
302
334
microcmdAuthUpdateOauth = cli.Command {
@@ -358,15 +390,15 @@ func runChangePassword(c *cli.Context) error {
358
390
return errors .New ("The password you chose is on a list of stolen passwords previously exposed in public data breaches. Please try again with a different password.\n For more details, see https://haveibeenpwned.com/Passwords" )
359
391
}
360
392
uname := c .String ("username" )
361
- user , err := models .GetUserByName (uname )
393
+ user , err := user_model .GetUserByName (uname )
362
394
if err != nil {
363
395
return err
364
396
}
365
397
if err = user .SetPassword (c .String ("password" )); err != nil {
366
398
return err
367
399
}
368
400
369
- if err = models .UpdateUserCols (user , "passwd" , "passwd_hash_algo" , "salt" ); err != nil {
401
+ if err = user_model .UpdateUserCols (db . DefaultContext , user , "passwd" , "passwd_hash_algo" , "salt" ); err != nil {
370
402
return err
371
403
}
372
404
@@ -424,15 +456,15 @@ func runCreateUser(c *cli.Context) error {
424
456
425
457
// If this is the first user being created.
426
458
// Take it as the admin and don't force a password update.
427
- if n := models .CountUsers (); n == 0 {
459
+ if n := user_model .CountUsers (); n == 0 {
428
460
changePassword = false
429
461
}
430
462
431
463
if c .IsSet ("must-change-password" ) {
432
464
changePassword = c .Bool ("must-change-password" )
433
465
}
434
466
435
- u := & models .User {
467
+ u := & user_model .User {
436
468
Name : username ,
437
469
Email : c .String ("email" ),
438
470
Passwd : password ,
@@ -442,7 +474,7 @@ func runCreateUser(c *cli.Context) error {
442
474
Theme : setting .UI .DefaultTheme ,
443
475
}
444
476
445
- if err := models .CreateUser (u ); err != nil {
477
+ if err := user_model .CreateUser (u ); err != nil {
446
478
return fmt .Errorf ("CreateUser: %v" , err )
447
479
}
448
480
@@ -471,7 +503,7 @@ func runListUsers(c *cli.Context) error {
471
503
return err
472
504
}
473
505
474
- users , err := models .GetAllUsers ()
506
+ users , err := user_model .GetAllUsers ()
475
507
476
508
if err != nil {
477
509
return err
@@ -516,13 +548,13 @@ func runDeleteUser(c *cli.Context) error {
516
548
}
517
549
518
550
var err error
519
- var user * models .User
551
+ var user * user_model .User
520
552
if c .IsSet ("email" ) {
521
- user , err = models .GetUserByEmail (c .String ("email" ))
553
+ user , err = user_model .GetUserByEmail (c .String ("email" ))
522
554
} else if c .IsSet ("username" ) {
523
- user , err = models .GetUserByName (c .String ("username" ))
555
+ user , err = user_model .GetUserByName (c .String ("username" ))
524
556
} else {
525
- user , err = models .GetUserByID (c .Int64 ("id" ))
557
+ user , err = user_model .GetUserByID (c .Int64 ("id" ))
526
558
}
527
559
if err != nil {
528
560
return err
@@ -624,7 +656,7 @@ func runRegenerateKeys(_ *cli.Context) error {
624
656
if err := initDB (ctx ); err != nil {
625
657
return err
626
658
}
627
- return models .RewriteAllPublicKeys ()
659
+ return asymkey_model .RewriteAllPublicKeys ()
628
660
}
629
661
630
662
func parseOAuth2Config (c * cli.Context ) * oauth2.Source {
@@ -647,6 +679,12 @@ func parseOAuth2Config(c *cli.Context) *oauth2.Source {
647
679
CustomURLMapping : customURLMapping ,
648
680
IconURL : c .String ("icon-url" ),
649
681
SkipLocalTwoFA : c .Bool ("skip-local-2fa" ),
682
+ Scopes : c .StringSlice ("scopes" ),
683
+ RequiredClaimName : c .String ("required-claim-name" ),
684
+ RequiredClaimValue : c .String ("required-claim-value" ),
685
+ GroupClaimName : c .String ("group-claim-name" ),
686
+ AdminGroup : c .String ("admin-group" ),
687
+ RestrictedGroup : c .String ("restricted-group" ),
650
688
}
651
689
}
652
690
@@ -709,6 +747,28 @@ func runUpdateOauth(c *cli.Context) error {
709
747
oAuth2Config .IconURL = c .String ("icon-url" )
710
748
}
711
749
750
+ if c .IsSet ("scopes" ) {
751
+ oAuth2Config .Scopes = c .StringSlice ("scopes" )
752
+ }
753
+
754
+ if c .IsSet ("required-claim-name" ) {
755
+ oAuth2Config .RequiredClaimName = c .String ("required-claim-name" )
756
+
757
+ }
758
+ if c .IsSet ("required-claim-value" ) {
759
+ oAuth2Config .RequiredClaimValue = c .String ("required-claim-value" )
760
+ }
761
+
762
+ if c .IsSet ("group-claim-name" ) {
763
+ oAuth2Config .GroupClaimName = c .String ("group-claim-name" )
764
+ }
765
+ if c .IsSet ("admin-group" ) {
766
+ oAuth2Config .AdminGroup = c .String ("admin-group" )
767
+ }
768
+ if c .IsSet ("restricted-group" ) {
769
+ oAuth2Config .RestrictedGroup = c .String ("restricted-group" )
770
+ }
771
+
712
772
// update custom URL mapping
713
773
var customURLMapping = & oauth2.CustomURLMapping {}
714
774
0 commit comments