mirror of
https://github.com/janishutz/oidclogin.git
synced 2026-10-08 17:26:20 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
59f635f01e | ||
|
|
d9ca3abb6c | ||
|
|
bc4abcf5e3 |
No files matched your search
@@ -128,6 +128,15 @@ func logoutHandler(c *gin.Context) {
|
||||
session := sessions.Default(c)
|
||||
session.Clear()
|
||||
session.Save()
|
||||
redir := ""
|
||||
if c.Query("returnTo") != "" {
|
||||
redir = c.Query("returnTo")
|
||||
}
|
||||
if redir != "" {
|
||||
c.Redirect(307, redir)
|
||||
} else {
|
||||
c.Redirect(307, defaultRedirect)
|
||||
}
|
||||
}
|
||||
|
||||
// Ensure that a user is currently logged in.
|
||||
|
||||
@@ -20,18 +20,28 @@ func createRandomString(n int) (string, error) {
|
||||
return base64.URLEncoding.EncodeToString(s), nil
|
||||
}
|
||||
|
||||
type UserFunc func(userid string, name string, email string)
|
||||
|
||||
var (
|
||||
config oauth2.Config
|
||||
userFunc func(userid string, name string, email string)
|
||||
userFunc UserFunc
|
||||
verifier oidc.IDTokenVerifier
|
||||
defaultRedirect string
|
||||
)
|
||||
|
||||
// Configure and set up the login SDK.
|
||||
// Wraps the normal configure function, but also gives you access to change the User Function, which is called upon login.
|
||||
// It is used to create or update a user.
|
||||
func ConfigureFull(r *gin.Engine, app_url string, default_redirect string, user_function UserFunc, stubs_on_unconfigured bool) {
|
||||
userFunc = user_function
|
||||
Configure(r, app_url, default_redirect, stubs_on_unconfigured)
|
||||
}
|
||||
|
||||
// Configure and set up the login SDK
|
||||
func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_unconfigured bool) {
|
||||
issuer := os.Getenv("OIDC_ISSUER")
|
||||
clientID := os.Getenv("OIDC_CLIENT_ID")
|
||||
clientSecret := os.Getenv("OIDC_CLIENT_SECRET")
|
||||
defaultRedirect = default_redirect
|
||||
|
||||
if issuer == "" || clientID == "" || clientSecret == "" {
|
||||
if stubs_on_unconfigured {
|
||||
@@ -45,7 +55,6 @@ func Configure(r *gin.Engine, app_url string, default_redirect string, stubs_on_
|
||||
|
||||
provider, err := oidc.NewProvider(context.Background(), issuer)
|
||||
verifier = *provider.Verifier(&oidc.Config{ClientID: clientID})
|
||||
defaultRedirect = default_redirect
|
||||
|
||||
if err != nil {
|
||||
log.Fatal("[JHID] Provider resolution failed with error", err)
|
||||
|
||||
Reference in new issue
Block a user