wip: 继续 oauth

This commit is contained in:
loveuer
2024-10-25 18:18:11 +08:00
parent a17b9bb16b
commit 4822fbc092
8 changed files with 270 additions and 87 deletions

34
internal/client/client.go Normal file
View File

@ -0,0 +1,34 @@
package client
import (
"context"
"github.com/google/uuid"
"golang.org/x/oauth2"
"golang.org/x/oauth2/authhandler"
)
var (
State = uuid.New().String()[:8]
)
func Run(ctx context.Context) error {
oauth2.NewClient(ctx, authhandler.TokenSource(
ctx,
&oauth2.Config{
ClientID: "",
ClientSecret: "",
Endpoint: oauth2.Endpoint{
AuthURL: "",
DeviceAuthURL: "",
TokenURL: "",
AuthStyle: 0,
},
RedirectURL: "",
Scopes: nil,
},
State,
func(authCodeURL string) (code string, state string, err error) {
},
))
}

View File

@ -0,0 +1,52 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<link
rel="stylesheet"
href="https://cdn.jsdelivr.net/npm/@picocss/pico@2/css/pico.min.css"
>
<title>Client Login</title>
<style>
body {
height: 100vh;
width: 100vw;
display: flex;
justify-content: center;
align-items: center;
}
</style>
</head>
<body>
<div>
<h3>这里是 xx 产品登录页面</h3>
<form>
<fieldset>
<label>
Username
<input
name="username"
placeholder="username"
autocomplete="given-name"
/>
</label>
<label>
Password
<input
type="password"
name="password"
placeholder="password"
autocomplete="password"
/>
</label>
</fieldset>
<input
type="submit"
value="登录"
/>
<a href="http://localhost:8080/api/oauth/v2/login?client_id=test&client_secret=test&scope=test1,test2&redirect_uri=http://localhost:9119/api/login/callback">使用 Pro 账号登录</a>
</form>
</div>
</body>
</html>