Add auth with goth
This commit is contained in:
40
internal/auth/auth.go
Normal file
40
internal/auth/auth.go
Normal file
@@ -0,0 +1,40 @@
|
||||
package auth
|
||||
import (
|
||||
"log"
|
||||
"os"
|
||||
//"github.com/gorilla/sessions"
|
||||
"github.com/joho/godotenv"
|
||||
"github.com/markbates/goth"
|
||||
//"github.com/markbates/goth/gothic"
|
||||
"github.com/markbates/goth/providers/openidConnect"
|
||||
)
|
||||
|
||||
const (
|
||||
key = "iebdyjckwoevhdixnwgwunrvxuqobetgy"
|
||||
MaxAge = 86400 * 30
|
||||
IsProd = false
|
||||
)
|
||||
|
||||
func NewAuth() {
|
||||
err := godotenv.Load()
|
||||
if err != nil {log.Fatal("Error loading .env file")}
|
||||
|
||||
oidcId := os.Getenv("OIDC_ID")
|
||||
oidcSec := os.Getenv("OIDC_SECRET")
|
||||
oidcDiscUrl := os.Getenv("OIDC_DISC_URL")
|
||||
oidcRedirectUrl := "http://localhost:3003/auth/openid-connect/callback"
|
||||
/*
|
||||
store := sessions.NewCookieStore([]byte(key))
|
||||
store.MaxAge(MaxAge)
|
||||
store.Options.Path = "/"
|
||||
store.Options.HttpOnly = true
|
||||
store.Options.Secure = IsProd
|
||||
|
||||
gothic.Store = store
|
||||
*/
|
||||
openidConnect, err := openidConnect.New(oidcId, oidcSec, oidcRedirectUrl, oidcDiscUrl)
|
||||
if openidConnect == nil || err != nil {
|
||||
log.Fatal("Error setting up oidc")
|
||||
}
|
||||
goth.UseProviders(openidConnect)
|
||||
}
|
||||
Reference in New Issue
Block a user