Skip to content

Commit

Permalink
feat: be & fe example
Browse files Browse the repository at this point in the history
  • Loading branch information
YiNNx committed Nov 2, 2023
1 parent fd16ed7 commit 86f350c
Show file tree
Hide file tree
Showing 11 changed files with 30,178 additions and 0 deletions.
16 changes: 16 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# 运行

- backend

```
go mod tidy
go run app.go
```

- frontend

```
npm install
npm
```

41 changes: 41 additions & 0 deletions example/backend/app.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package main

import (
"log"
"net/http"

"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"

"github.com/BingyanStudio/oidc-cli/oidc"
)

var oidcCli = oidc.NewClient(
&oidc.Config{
ClientID: "CLIENT_ID",
ClientSecret: "CLIENT_SECRET",
RedirectURL: "http://localhost:3000/callback", // Frontend Callback URI
},
)

func UserTokenHandler(c echo.Context) error {
code := c.QueryParam("code")
tokens, err := oidcCli.RetrieveTokens(code)
if err != nil {
log.Printf("err: " + err.Error())
return c.String(http.StatusInternalServerError, "Internal Server Error")
}

log.Println(tokens)

// use the tokens & claims to further authorization

return c.JSON(http.StatusOK, tokens)
}

func main() {
e := echo.New()
e.Use(middleware.CORS())
e.GET("/user/token", UserTokenHandler)
e.Start(":8000")
}
Loading

0 comments on commit 86f350c

Please sign in to comment.