fix(exampleop): pass the issuer interceptor to login (#430)
* fix(exampleop): pass the issuer interceptor to login * undo example testing changes
This commit is contained in:
parent
4ed269979e
commit
ce85a8b820
2 changed files with 9 additions and 7 deletions
|
@ -6,6 +6,7 @@ import (
|
||||||
"net/http"
|
"net/http"
|
||||||
|
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
|
"github.com/zitadel/oidc/v2/pkg/op"
|
||||||
)
|
)
|
||||||
|
|
||||||
type login struct {
|
type login struct {
|
||||||
|
@ -14,19 +15,19 @@ type login struct {
|
||||||
callback func(context.Context, string) string
|
callback func(context.Context, string) string
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewLogin(authenticate authenticate, callback func(context.Context, string) string) *login {
|
func NewLogin(authenticate authenticate, callback func(context.Context, string) string, issuerInterceptor *op.IssuerInterceptor) *login {
|
||||||
l := &login{
|
l := &login{
|
||||||
authenticate: authenticate,
|
authenticate: authenticate,
|
||||||
callback: callback,
|
callback: callback,
|
||||||
}
|
}
|
||||||
l.createRouter()
|
l.createRouter(issuerInterceptor)
|
||||||
return l
|
return l
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *login) createRouter() {
|
func (l *login) createRouter(issuerInterceptor *op.IssuerInterceptor) {
|
||||||
l.router = mux.NewRouter()
|
l.router = mux.NewRouter()
|
||||||
l.router.Path("/username").Methods("GET").HandlerFunc(l.loginHandler)
|
l.router.Path("/username").Methods("GET").HandlerFunc(l.loginHandler)
|
||||||
l.router.Path("/username").Methods("POST").HandlerFunc(l.checkLoginHandler)
|
l.router.Path("/username").Methods("POST").HandlerFunc(issuerInterceptor.HandlerFunc(l.checkLoginHandler))
|
||||||
}
|
}
|
||||||
|
|
||||||
type authenticate interface {
|
type authenticate interface {
|
||||||
|
|
|
@ -55,9 +55,10 @@ func SetupServer(issuer string, storage Storage, extraOptions ...op.Option) *mux
|
||||||
log.Fatal(err)
|
log.Fatal(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
// the provider will only take care of the OpenID Protocol, so there must be some sort of UI for the login process
|
//the provider will only take care of the OpenID Protocol, so there must be some sort of UI for the login process
|
||||||
// for the simplicity of the example this means a simple page with username and password field
|
//for the simplicity of the example this means a simple page with username and password field
|
||||||
l := NewLogin(storage, op.AuthCallbackURL(provider))
|
//be sure to provide an IssuerInterceptor with the IssuerFromRequest from the OP so the login can select / and pass it to the storage
|
||||||
|
l := NewLogin(storage, op.AuthCallbackURL(provider), op.NewIssuerInterceptor(provider.IssuerFromRequest))
|
||||||
|
|
||||||
// regardless of how many pages / steps there are in the process, the UI must be registered in the router,
|
// regardless of how many pages / steps there are in the process, the UI must be registered in the router,
|
||||||
// so we will direct all calls to /login to the login UI
|
// so we will direct all calls to /login to the login UI
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue