Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add config struct of OpenID-Connect Login #2597

Merged
merged 8 commits into from
Aug 29, 2022
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions api/conf/conf.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,17 @@ authentication:
- username: user
password: user

oidc:
secret:
secret
expire_time: 3600
apps:
- app_name: authing
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we can support one app first.
So just remove apps.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok

client_id:
client_secret:
scope: oidc
redirect_uri: /authing/callback
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

redirect_uri shouldn't contain the authing config.
Maybe oidc/callback.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok


plugins: # plugin list (sorted in alphabetical order)
- api-breaker
- authz-keycloak
Expand Down
33 changes: 33 additions & 0 deletions api/internal/conf/conf.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,8 @@ var (
AccessLogPath = "logs/access.log"
UserList = make(map[string]User, 2)
AuthConf Authentication
AppList = make(map[string]App, 1)
OidcConf Oidc
SSLDefaultStatus = 1 //enable ssl by default
ImportSizeLimit = 10 * 1024 * 1024
AllowList []string
Expand Down Expand Up @@ -126,10 +128,25 @@ type Authentication struct {
Users []User
}

type App struct {
AppName string `mapstructure:"app_name"`
ClientId string `mapstructure:"client_id"`
ClientSecret string `mapstructure:"client_secret"`
Scope string
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to add mapstructure of this field?

RedirectUri string `mapstructure:"redirect_uri"`
}

type Oidc struct {
Secret string
ExpireTime int `mapstructure:"expire_time" yaml:"expire_time"`
Apps []App
}

type Config struct {
Conf Conf
Authentication Authentication
Plugins []string
Oidc Oidc
}

type Security struct {
Expand Down Expand Up @@ -256,6 +273,9 @@ func setupConfig() {
// set authentication
initAuthentication(config.Authentication)

//set Oidc
initOidc(config.Oidc)

// set plugin
initPlugins(config.Plugins)

Expand Down Expand Up @@ -283,6 +303,19 @@ func initAuthentication(conf Authentication) {
}
}

func initOidc(conf Oidc) {
OidcConf = conf

if OidcConf.Secret == "secret" {
OidcConf.Secret = utils.GetFlakeUidStr()
}
appList := OidcConf.Apps

for _, item := range appList {
AppList[item.AppName] = item
}
}

func initPlugins(plugins []string) {
for _, pluginName := range plugins {
Plugins[pluginName] = true
Expand Down
5 changes: 1 addition & 4 deletions api/internal/filter/invalid_request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,5 @@ func InvalidRequest() gin.HandlerFunc {
}

func checkURL(url *url.URL) bool {
if strings.Contains(url.Path, "..") {
return false
}
return true
return !strings.Contains(url.Path, "..")
}
3 changes: 1 addition & 2 deletions api/internal/handler/data_loader/loader/openapi3/import.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,7 @@ func (o Loader) convertToEntities(s *openapi3.Swagger) (*loader.DataSets, error)

// create upstream when servers field not empty
if len(s.Servers) > 0 {
var upstream entity.Upstream
upstream = entity.Upstream{
upstream := entity.Upstream{
BaseInfo: entity.BaseInfo{ID: globalUpstreamID},
UpstreamDef: entity.UpstreamDef{
Name: globalUpstreamID,
Expand Down
1 change: 0 additions & 1 deletion api/internal/handler/data_loader/route_import.go
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,6 @@ func (h *ImportHandler) Import(c droplet.Context) (interface{}, error) {
MergeMethod: input.MergeMethod == "true",
TaskName: input.TaskName,
}
break
default:
return nil, fmt.Errorf("unsupported data loader type: %s", input.Type)
}
Expand Down