You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
59 lines
948 B
Go
59 lines
948 B
Go
5 years ago
|
package main
|
||
|
|
||
|
// Small generic oauth authentication server to retrieve oauth tokens
|
||
|
// from mastodon instances.
|
||
|
|
||
|
import (
|
||
|
"github.com/gorilla/websocket"
|
||
|
"github.com/labstack/echo"
|
||
|
"github.com/labstack/echo/middleware"
|
||
|
)
|
||
|
|
||
|
// github.com/oklog/ulid
|
||
|
|
||
|
var (
|
||
|
upgrader = websocket.Upgrader{}
|
||
|
)
|
||
|
|
||
|
type App struct {
|
||
|
AuthQueue *AuthenticationQueue
|
||
|
}
|
||
|
|
||
|
func (a *App) authRequestWebSocket(c echo.Context) error {
|
||
|
ws, err := upgrader.Upgrade(c.Response(), c.Request(), nil)
|
||
|
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
client := &AuthRequestClient{
|
||
|
conn: ws,
|
||
|
}
|
||
|
|
||
|
req, err := client.ReceiveRequest()
|
||
|
|
||
|
if err != nil {
|
||
|
return err
|
||
|
}
|
||
|
|
||
|
a.AuthQueue.QueueRequest(req)
|
||
|
return nil
|
||
|
}
|
||
|
|
||
|
func main() {
|
||
|
q := &AuthenticationQueue{}
|
||
|
|
||
|
q.startRequestChanListener()
|
||
|
|
||
|
a := &App{
|
||
|
AuthQueue: q,
|
||
|
}
|
||
|
|
||
|
e := echo.New()
|
||
|
e.Use(middleware.Logger())
|
||
|
e.Use(middleware.Recover())
|
||
|
e.Static("/", "../public")
|
||
|
e.GET("/ws", a.authRequestWebSocket)
|
||
|
e.Logger.Fatal(e.Start(":1323"))
|
||
|
}
|