mirror of
https://github.com/yudai/gotty.git
synced 2026-03-13 08:56:14 +01:00
Use credential for auth_token
This commit is contained in:
parent
0bd2f3f2c8
commit
ff92777011
2 changed files with 6 additions and 7 deletions
11
app/app.go
11
app/app.go
|
|
@ -29,9 +29,8 @@ type App struct {
|
|||
command []string
|
||||
options *Options
|
||||
|
||||
upgrader *websocket.Upgrader
|
||||
server *manners.GracefulServer
|
||||
authToken string
|
||||
upgrader *websocket.Upgrader
|
||||
server *manners.GracefulServer
|
||||
|
||||
titleTemplate *template.Template
|
||||
}
|
||||
|
|
@ -89,7 +88,6 @@ func New(command []string, options *Options) (*App, error) {
|
|||
WriteBufferSize: 1024,
|
||||
Subprotocols: []string{"gotty"},
|
||||
},
|
||||
authToken: generateRandomString(20),
|
||||
|
||||
titleTemplate: titleTemplate,
|
||||
}, nil
|
||||
|
|
@ -253,8 +251,9 @@ func (app *App) handleWS(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
_, initMessage, err := conn.ReadMessage()
|
||||
if err != nil || string(initMessage) != app.authToken {
|
||||
if err != nil || string(initMessage) != app.options.Credential {
|
||||
log.Print("Failed to authenticate websocket connection")
|
||||
conn.Close()
|
||||
return
|
||||
}
|
||||
|
||||
|
|
@ -282,7 +281,7 @@ func (app *App) handleCustomIndex(w http.ResponseWriter, r *http.Request) {
|
|||
}
|
||||
|
||||
func (app *App) handleAuthToken(w http.ResponseWriter, r *http.Request) {
|
||||
w.Write([]byte("var gotty_auth_token = '" + app.authToken + "';"))
|
||||
w.Write([]byte("var gotty_auth_token = '" + app.options.Credential + "';"))
|
||||
}
|
||||
|
||||
func (app *App) Exit() (firstCall bool) {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue