()
| 44 | } |
| 45 | |
| 46 | func (app *BootstrapApp) Setup() error { |
| 47 | fmt.Println("Tinyauth is moving to an organization! All versions after v5.0.7 will be released under ghcr.io/tinyauthapp/tinyauth. Existing images will continue to work but new features and updates (including security ones) will only be released under the new image path.") |
| 48 | |
| 49 | // get app url |
| 50 | if app.config.AppURL == "" { |
| 51 | return fmt.Errorf("app URL cannot be empty, perhaps config loading failed") |
| 52 | } |
| 53 | |
| 54 | appUrl, err := url.Parse(app.config.AppURL) |
| 55 | |
| 56 | if err != nil { |
| 57 | return err |
| 58 | } |
| 59 | |
| 60 | app.context.appUrl = appUrl.Scheme + "://" + appUrl.Host |
| 61 | |
| 62 | // validate session config |
| 63 | if app.config.Auth.SessionMaxLifetime != 0 && app.config.Auth.SessionMaxLifetime < app.config.Auth.SessionExpiry { |
| 64 | return fmt.Errorf("session max lifetime cannot be less than session expiry") |
| 65 | } |
| 66 | |
| 67 | // Parse users |
| 68 | users, err := utils.GetUsers(app.config.Auth.Users, app.config.Auth.UsersFile) |
| 69 | |
| 70 | if err != nil { |
| 71 | return err |
| 72 | } |
| 73 | |
| 74 | app.context.users = users |
| 75 | |
| 76 | // Setup OAuth providers |
| 77 | app.context.oauthProviders = app.config.OAuth.Providers |
| 78 | |
| 79 | for name, provider := range app.context.oauthProviders { |
| 80 | secret := utils.GetSecret(provider.ClientSecret, provider.ClientSecretFile) |
| 81 | provider.ClientSecret = secret |
| 82 | provider.ClientSecretFile = "" |
| 83 | |
| 84 | if provider.RedirectURL == "" { |
| 85 | provider.RedirectURL = app.context.appUrl + "/api/oauth/callback/" + name |
| 86 | } |
| 87 | |
| 88 | app.context.oauthProviders[name] = provider |
| 89 | } |
| 90 | |
| 91 | for id, provider := range app.context.oauthProviders { |
| 92 | if provider.Name == "" { |
| 93 | if name, ok := config.OverrideProviders[id]; ok { |
| 94 | provider.Name = name |
| 95 | } else { |
| 96 | provider.Name = utils.Capitalize(id) |
| 97 | } |
| 98 | } |
| 99 | app.context.oauthProviders[id] = provider |
| 100 | } |
| 101 | |
| 102 | // Setup OIDC clients |
| 103 | for id, client := range app.config.OIDC.Clients { |
no test coverage detected