2019-09-28 20:04:51 -04:00
|
|
|
package auth
|
|
|
|
|
|
|
|
import (
|
|
|
|
"net/http"
|
|
|
|
|
|
|
|
"github.com/codegangsta/negroni"
|
2019-11-09 11:13:14 -05:00
|
|
|
_http "github.com/jchenry/jchenry/http"
|
2019-10-09 11:56:57 -04:00
|
|
|
"gopkg.in/auth0.v1/management"
|
2019-09-28 20:04:51 -04:00
|
|
|
)
|
|
|
|
|
|
|
|
func Service(c Config) ServiceInstance {
|
|
|
|
return ServiceInstance{c: c}
|
|
|
|
}
|
|
|
|
|
|
|
|
type ServiceInstance struct {
|
|
|
|
c Config
|
|
|
|
}
|
|
|
|
|
2019-11-09 11:13:14 -05:00
|
|
|
func (si ServiceInstance) Register(uriBase string, s *_http.Server) {
|
2019-09-28 20:04:51 -04:00
|
|
|
|
2019-11-06 22:40:38 -05:00
|
|
|
s.Get(uriBase+"/login", "login endpoint", http.HandlerFunc(NewLoginHandler(si.c)))
|
|
|
|
s.Get(uriBase+"/logout", "logout endpoint", http.HandlerFunc(LogoutHandler))
|
|
|
|
s.Get(uriBase+"/callback", "oidc callback", http.HandlerFunc(NewCallbackHandler(si.c)))
|
|
|
|
s.Get(uriBase+"/user", "user info endpoint", negroni.New(
|
2019-09-28 20:04:51 -04:00
|
|
|
negroni.HandlerFunc(IsAuthenticated),
|
|
|
|
negroni.Wrap(http.HandlerFunc(UserHandler)),
|
|
|
|
))
|
|
|
|
}
|
2019-10-09 11:56:57 -04:00
|
|
|
|
|
|
|
func (si ServiceInstance) UpdateUser(u User) error {
|
|
|
|
m, err := management.New(si.c.Domain, si.c.ManagementClientID, si.c.ManagementClientSecret)
|
|
|
|
if err != nil {
|
|
|
|
return err
|
|
|
|
}
|
|
|
|
|
|
|
|
um := management.NewUserManager(m)
|
|
|
|
|
|
|
|
return um.Update(u.ID, &management.User{AppMetadata: u.Apps})
|
|
|
|
}
|