-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
30,178 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
``` | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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") | ||
} |
Oops, something went wrong.