mirror of https://github.com/synctv-org/synctv
Feat: oauth2 api
parent
dab669708d
commit
3f1116e2e2
@ -0,0 +1,32 @@
|
||||
package model
|
||||
|
||||
import (
|
||||
"errors"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
json "github.com/json-iterator/go"
|
||||
)
|
||||
|
||||
type OAuth2CallbackReq struct {
|
||||
Code string `json:"code"`
|
||||
State string `json:"state"`
|
||||
}
|
||||
|
||||
var (
|
||||
ErrInvalidOAuth2Code = errors.New("invalid oauth2 code")
|
||||
ErrInvalidOAuth2State = errors.New("invalid oauth2 state")
|
||||
)
|
||||
|
||||
func (o *OAuth2CallbackReq) Validate() error {
|
||||
if o.Code == "" {
|
||||
return ErrInvalidOAuth2Code
|
||||
}
|
||||
if o.State == "" {
|
||||
return ErrInvalidOAuth2State
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
func (o *OAuth2CallbackReq) Decode(ctx *gin.Context) error {
|
||||
return json.NewDecoder(ctx.Request.Body).Decode(o)
|
||||
}
|
@ -0,0 +1,13 @@
|
||||
package auth
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"github.com/synctv-org/synctv/internal/conf"
|
||||
"golang.org/x/exp/maps"
|
||||
)
|
||||
|
||||
func OAuth2EnabledApi(ctx *gin.Context) {
|
||||
ctx.JSON(200, gin.H{
|
||||
"enabled": maps.Keys(conf.Conf.OAuth2),
|
||||
})
|
||||
}
|
@ -0,0 +1,16 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="zh-CN">
|
||||
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta http-equiv="X-UA-Compatible" content="IE=edge">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Redirecting..</title>
|
||||
</head>
|
||||
|
||||
<body>
|
||||
<p>If you are not redirected, please click <a href="{{ .Url }}">here</a>.</p>
|
||||
<script>localStorage.setItem("userToken", "{{ .Token }}"); window.location.href = "{{ .Url }}"</script>
|
||||
</body>
|
||||
|
||||
</html>
|
Loading…
Reference in New Issue