Skip to content

Commit ce5565b

Browse files
author
Jannis Pohlmann
committed
connections, handler: Rename UserFromAuthFunc to Authenticate
This function name feels a little less stuttery and more familiar.
1 parent b58f6c3 commit ce5565b

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

connections.go

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ func (msg OperationMessage) String() string {
6666
return "<invalid>"
6767
}
6868

69-
// UserFromAuthTokenFunc is a function that resolves an auth token
69+
// AuthenticateFunc is a function that resolves an auth token
7070
// into a user (or returns an error if that isn't possible).
71-
type UserFromAuthTokenFunc func(token string) (interface{}, error)
71+
type AuthenticateFunc func(token string) (interface{}, error)
7272

7373
// ConnectionEventHandlers define the event handlers for a connection.
7474
// Event handlers allow other system components to react to events such
@@ -95,8 +95,8 @@ type ConnectionEventHandlers struct {
9595
// ConnectionConfig defines the configuration parameters of a
9696
// GraphQL WebSocket connection.
9797
type ConnectionConfig struct {
98-
UserFromAuthToken UserFromAuthTokenFunc
99-
EventHandlers ConnectionEventHandlers
98+
Authenticate AuthenticateFunc
99+
EventHandlers ConnectionEventHandlers
100100
}
101101

102102
// Connection is an interface to represent GraphQL WebSocket connections.
@@ -268,8 +268,8 @@ func (conn *connection) readLoop() {
268268
if err := json.Unmarshal(rawPayload, &data); err != nil {
269269
conn.SendError(errors.New("Invalid GQL_CONNECTION_INIT payload"))
270270
} else {
271-
if conn.config.UserFromAuthToken != nil {
272-
user, err := conn.config.UserFromAuthToken(data.AuthToken)
271+
if conn.config.Authenticate != nil {
272+
user, err := conn.config.Authenticate(data.AuthToken)
273273
if err != nil {
274274
conn.SendError(fmt.Errorf("Failed to authenticate user: %v", err))
275275
} else {

examples/simple-server/main.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ func main() {
3333
subscriptionManager := graphqlws.NewSubscriptionManager(&schema)
3434
websocketHandler := graphqlws.NewHandler(graphqlws.HandlerConfig{
3535
SubscriptionManager: subscriptionManager,
36-
UserFromAuthToken: func(token string) (interface{}, error) {
36+
Authenticate: func(token string) (interface{}, error) {
3737
return "Default user", nil
3838
},
3939
})

handler.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
// HandlerConfig stores the configuration of a GraphQL WebSocket handler.
1111
type HandlerConfig struct {
1212
SubscriptionManager SubscriptionManager
13-
UserFromAuthToken UserFromAuthTokenFunc
13+
Authenticate AuthenticateFunc
1414
}
1515

1616
// NewHandler creates a WebSocket handler for GraphQL WebSocket connections.
@@ -50,7 +50,7 @@ func NewHandler(config HandlerConfig) http.Handler {
5050

5151
// Establish a GraphQL WebSocket connection
5252
conn := NewConnection(ws, ConnectionConfig{
53-
UserFromAuthToken: config.UserFromAuthToken,
53+
Authenticate: config.Authenticate,
5454
EventHandlers: ConnectionEventHandlers{
5555
Close: func(conn Connection) {
5656
logger.WithFields(log.Fields{

0 commit comments

Comments
 (0)