File size: 1,507 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
package app

import (
	"context"

	"github.com/pkg/errors"
	"github.com/target/goalert/auth"
	"github.com/target/goalert/auth/basic"
	"github.com/target/goalert/auth/github"
	"github.com/target/goalert/auth/oidc"
)

func (app *App) initAuth(ctx context.Context) error {

	var err error
	app.AuthHandler, err = auth.NewHandler(ctx, app.db, auth.HandlerConfig{
		UserStore:      app.UserStore,
		SessionKeyring: app.SessionKeyring,
		IntKeyStore:    app.IntegrationKeyStore,
		CalSubStore:    app.CalSubStore,
		APIKeyring:     app.APIKeyring,
		APIKeyStore:    app.APIKeyStore,
	})
	if err != nil {
		return errors.Wrap(err, "init auth handler")
	}

	cfg := oidc.Config{
		Keyring:    app.OAuthKeyring,
		NonceStore: app.NonceStore,
	}
	oidcProvider, err := oidc.NewProvider(ctx, cfg)
	if err != nil {
		return errors.Wrap(err, "init OIDC auth provider")
	}
	if err := app.AuthHandler.AddIdentityProvider("oidc", oidcProvider); err != nil {
		return err
	}

	githubConfig := &github.Config{
		Keyring:    app.OAuthKeyring,
		NonceStore: app.NonceStore,
	}

	githubProvider, err := github.NewProvider(ctx, githubConfig)
	if err != nil {
		return errors.Wrap(err, "init GitHub auth provider")
	}
	if err := app.AuthHandler.AddIdentityProvider("github", githubProvider); err != nil {
		return err
	}

	basicProvider, err := basic.NewProvider(ctx, app.AuthBasicStore)
	if err != nil {
		return errors.Wrap(err, "init basic auth provider")
	}
	return app.AuthHandler.AddIdentityProvider("basic", basicProvider)
}