mirror of
https://github.com/janishutz/oidclogin.git
synced 2026-10-08 17:26:20 +02:00
chore: add usage to readme
This commit is contained in:
1 parent
d744f68b12
commit
0c4a463052
1 file changed
+34
@@ -8,3 +8,37 @@ OIDC_CLIENT_SECRET=<client secret>
|
|||||||
OIDC_ISSUE=<issuer url>
|
OIDC_ISSUE=<issuer url>
|
||||||
```
|
```
|
||||||
If these env vars are not present, then depending on configuration, stubs will be used for the endpoints or the program will crash
|
If these env vars are not present, then depending on configuration, stubs will be used for the endpoints or the program will crash
|
||||||
|
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
```go
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"os"
|
||||||
|
|
||||||
|
"github.com/gin-contrib/sessions"
|
||||||
|
"github.com/gin-contrib/sessions/memstore"
|
||||||
|
"github.com/gin-gonic/gin"
|
||||||
|
"github.com/janishutz/oidclogin"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
r := gin.Default()
|
||||||
|
|
||||||
|
// TODO: Better secret
|
||||||
|
store := memstore.NewStore([]byte("secret"))
|
||||||
|
r.Use(sessions.Sessions("jhid", store))
|
||||||
|
|
||||||
|
oidclogin.Configure(r, os.Getenv("APP_BASE_URL"), "/account", false)
|
||||||
|
r.LoadHTMLGlob("public/*")
|
||||||
|
|
||||||
|
r.GET("/account", oidclogin.EnsureLogin(false), func(ctx *gin.Context) {
|
||||||
|
ctx.HTML(200, "main.tmpl", gin.H{})
|
||||||
|
})
|
||||||
|
|
||||||
|
r.Run()
|
||||||
|
}
|
||||||
|
```
|
||||||
|
This example further needs the environment variable `APP_BASE_URL` set to something like `https://app.example.org`.
|
||||||
|
Further, you should create a template file called `main.tmpl` and also copy over the template files in the `public` directory here and edit them.
|
||||||
Reference in new issue
Block a user