Skip to content

Commit d22fa62

Browse files
authored
Merge pull request #1 from castaneai/detail-unauth-error
fix unauthenticated response
2 parents 32032db + c2f9502 commit d22fa62

File tree

1 file changed

+11
-10
lines changed

1 file changed

+11
-10
lines changed

server.go

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -21,10 +21,6 @@ const (
2121
redisOperationTimeout = 10 * time.Second
2222
)
2323

24-
var (
25-
errUnauthenticated = errors.New("unauthenticated")
26-
)
27-
2824
type clientProxy struct {
2925
roomID RoomID
3026
clientID ClientID
@@ -309,16 +305,21 @@ func (s *Server) authn(conn *websocket.Conn) (*clientProxy, error) {
309305
defer cancel()
310306
authnResponse, err := authn.Authenticate(ctx, req)
311307
if err != nil {
308+
_ = s.writeJSON(conn, &RejectMessage{
309+
Type: MessageTypeReject,
310+
Reason: "InternalServerError",
311+
})
312312
return nil, fmt.Errorf("failed to authenticate: %w", err)
313313
}
314314
if !authnResponse.Allowed {
315-
if err := s.writeJSON(conn, &RejectMessage{
315+
// Although Ayame returns an InternalServerError, Ayu respects the Reason of the Authenticator.
316+
// This is to distinguish between an InternalServerError and a denial of authentication.
317+
// ref: https://github.com/OpenAyame/ayame/blob/9edb22807aca5a3c50d3b2444b370e5ee55012fd/connection.go#L332
318+
_ = s.writeJSON(conn, &RejectMessage{
316319
Type: MessageTypeReject,
317-
Reason: "InternalServerError",
318-
}); err != nil {
319-
return nil, fmt.Errorf("failed to send reject message: %w", err)
320-
}
321-
return nil, errUnauthenticated
320+
Reason: authnResponse.Reason,
321+
})
322+
return nil, fmt.Errorf("unauthenticated (reason: %s)", authnResponse.Reason)
322323
}
323324
s.logger.Infof("authenticated (room: %s, client: %s)", req.RoomID, req.ClientID)
324325
return &clientProxy{

0 commit comments

Comments
 (0)