Example #1
0
func setupAuthApps(authrouter *mux.Router, usermgr UserManager) {
	for _, authkey := range options.AuthKeys {
		authconfig, ok := (*options.AuthConfigs)[authkey.Name]
		if !ok {
			log.Printf("Unknown authenticator \"%s\", skipping", authkey.Name)
			continue
		}
		authconfig.AuthKey = authkey

		var auth Authenticator
		var ex Extractor
		prefix, _ := authrouter.Path("/" + authkey.Name).URL()
		switch authconfig.Extractor.Type {
		case "json":
			ex = NewJSONExtractor(authconfig.Extractor.URL, authconfig.Extractor.Field)
		default:
			log.Printf("Unknown extractor \"%s\", skipping", authconfig.Extractor.Type)
			continue
		}
		switch authconfig.Type {
		case "oauth":
			log.Printf("Enabling %s OAuth on %s with ClientID %s", authkey.Name, prefix.String(), authconfig.AuthKey.ClientID)
			auth = NewOAuthAuthenticator(authkey.Name, &oauth.Config{
				ClientId:     authconfig.AuthKey.ClientID,
				ClientSecret: authconfig.AuthKey.Secret,
				AuthURL:      authconfig.AuthURL,
				TokenURL:     authconfig.TokenURL,
				Scope:        authconfig.Scope,
				RedirectURL:  prefix.String() + "/callback",
			}, ex, usermgr)
		default:
			log.Printf("Unknown authenticator \"%s\", skipping", authconfig.Type)
			continue
		}
		authrouter.PathPrefix("/" + authkey.Name).Handler(
			context.ClearHandler(HandlerList{
				SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
				http.StripPrefix(prefix.Path, auth),
			}))
	}
	authrouter.Handle("/", authListHandler(options.AuthConfigs))
	authrouter.Path("/logout").Handler(
		context.ClearHandler(HandlerList{
			SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
			http.HandlerFunc(LogoutHandler),
		}))
}
Example #2
0
func setupApiApps(apirouter *mux.Router, domainmgr DomainManager, usermgr UserManager) {
	prefix, _ := apirouter.Path("/").URL()
	apirouter.PathPrefix("/v1").Handler(
		context.ClearHandler(HandlerList{
			SilentHandler(SessionHandler(options.SessionStore, int(options.SessionTTL/time.Second))),
			SilentHandler(BasicAuth(usermgr)),
			SilentHandler(ValidateUID(usermgr)),
			http.StripPrefix(prefix.Path+"v1", NewAPIv1(domainmgr, usermgr)),
		}))
}