sourcegraph/cmd/frontend/internal/auth/githuboauth/middleware.go
Erik Seliger 7a116a2a15
Merge enterprise and oss frontend (#56476)
This is a big one! Merged the enterprise frontend with the OSS one, to get yet another step closer to getting rid of the enterprise directory :)
2023-09-11 14:16:38 +02:00

31 lines
818 B
Go

package githuboauth
import (
"net/http"
"github.com/sourcegraph/sourcegraph/cmd/frontend/auth"
"github.com/sourcegraph/sourcegraph/cmd/frontend/internal/auth/oauth"
"github.com/sourcegraph/sourcegraph/internal/database"
"github.com/sourcegraph/sourcegraph/internal/extsvc"
"github.com/sourcegraph/sourcegraph/schema"
)
const authPrefix = auth.AuthURLPrefix + "/github"
func init() {
oauth.AddIsOAuth(func(p schema.AuthProviders) bool {
return p.Github != nil
})
}
func Middleware(db database.DB) *auth.Middleware {
return &auth.Middleware{
API: func(next http.Handler) http.Handler {
return oauth.NewMiddleware(db, extsvc.TypeGitHub, authPrefix, true, next)
},
App: func(next http.Handler) http.Handler {
return oauth.NewMiddleware(db, extsvc.TypeGitHub, authPrefix, false, next)
},
}
}