@@ -28,57 +28,58 @@ func Start(logger *logrus.Entry, version string, cfg *config.ServiceConfig) erro
28
28
return fmt .Errorf ("failed to initialize IAM server: %w" , err )
29
29
}
30
30
31
- // All root requests are handled by our router
32
- rootHandler , err := registerRootRouter (srv )
31
+ oidcService := oidc . NewOIDCService ()
32
+ err = register (srv , oidcService )
33
33
if err != nil {
34
34
return fmt .Errorf ("failed to register services to iam server" )
35
35
}
36
36
37
- // Requests to /oidc/* are handled by oidc.Router
38
- oidcService := oidc .NewOIDCService ()
39
- rootHandler .Mount ("/oidc" , oidc .Router (oidcService ))
40
-
41
37
// TODO(at) remove the demo config after start sync'ing with DB
42
- err = loadTestConfig (oidcService , cfg )
38
+ clientConfig , err : = loadTestConfig (cfg . OIDCClientsConfigFile )
43
39
if err != nil {
44
40
return fmt .Errorf ("failed to load test config" )
45
41
}
46
42
43
+ err = oidcService .AddClientConfig (clientConfig )
44
+ if err != nil {
45
+ return fmt .Errorf ("failed to add client config to oidc service: %w" , err )
46
+ }
47
+
47
48
if listenErr := srv .ListenAndServe (); listenErr != nil {
48
49
return fmt .Errorf ("failed to serve iam server: %w" , listenErr )
49
50
}
50
51
51
52
return nil
52
53
}
53
54
54
- func registerRootRouter (srv * baseserver.Server ) ( * chi. Mux , error ) {
55
- rootHandler := chi .NewRouter ()
55
+ func register (srv * baseserver.Server , oidcSvc * oidc. OIDCService ) error {
56
+ root := chi .NewRouter ()
56
57
57
- srv .HTTPMux ().Handle ("/" , rootHandler )
58
- return rootHandler , nil
58
+ root .Mount ("/oidc" , oidc .Router (oidcSvc ))
59
+
60
+ // All root requests are handled by our router
61
+ srv .HTTPMux ().Handle ("/" , root )
62
+ return nil
59
63
}
60
64
61
65
// TODO(at) remove the demo config after start sync'ing with DB
62
- func loadTestConfig (oidcService * oidc.OIDCService , cfg * config. ServiceConfig ) error {
63
- testConfig , err := oidc .ReadDemoConfigFromFile (cfg . OIDCClientsConfigFile )
66
+ func loadTestConfig (clientsConfigFilePath string ) ( * oidc.OIDCClientConfig , error ) {
67
+ testConfig , err := oidc .ReadDemoConfigFromFile (clientsConfigFilePath )
64
68
if err != nil {
65
- return fmt .Errorf ("failed to read test config: %w" , err )
66
- }
67
- oidcConfig := & goidc.Config {
68
- ClientID : testConfig .ClientID ,
69
+ return nil , fmt .Errorf ("failed to read test config: %w" , err )
69
70
}
70
- oauth2Config := & oauth2. Config {
71
- ClientID : testConfig . ClientID ,
72
- ClientSecret : testConfig .ClientSecret ,
73
- RedirectURL : testConfig . RedirectURL ,
74
- Scopes : [] string { goidc . ScopeOpenID , "profile" , "email" },
75
- }
76
- clientConfig := & oidc. OIDCClientConfig {
77
- Issuer : testConfig .Issuer ,
78
- ID : "R4ND0M1D" ,
79
- OAuth2Config : oauth2Config ,
80
- OIDCConfig : oidcConfig ,
81
- }
82
- err = oidcService . AddClientConfig ( clientConfig )
83
- return err
71
+
72
+ return & oidc. OIDCClientConfig {
73
+ Issuer : testConfig .Issuer ,
74
+ ID : "R4ND0M1D" ,
75
+ OAuth2Config : & oauth2. Config {
76
+ ClientID : testConfig . ClientID ,
77
+ ClientSecret : testConfig . ClientSecret ,
78
+ RedirectURL : testConfig .RedirectURL ,
79
+ Scopes : [] string { goidc . ScopeOpenID , "profile" , "email" } ,
80
+ } ,
81
+ OIDCConfig : & goidc. Config {
82
+ ClientID : testConfig . ClientID ,
83
+ },
84
+ }, nil
84
85
}
0 commit comments