Sorry for the late response. I was a little occupied in the last few months.
I have been working on the project again and made a lot of breaking changes as you can see here Lambda Server in Go - #7 by Schartey
I would be really glad if you could leave some feedback if you end up using the library. I have still a lot of testing to do, but the basic features should be working fine as I am also using it in my own project.
In terms of JWT generation, here is an example when using my lambda server:
Schema:
type AuthResponse @generate(
query: {
get: false,
query: false,
aggregate: false
},
mutation: {
add: false,
delete: false
},
subscription: false
) {
user: User
token: String
expiration: DateTime
}
type Mutation {
login(username: String, password: String): AuthResponse! @lambda
}
JWT generation in generated login mutation resolver using github.com/dgrijalva/jwt-go
func (q *MutationResolver) Mutation_login(ctx context.Context, username string, password string, authHeader api.AuthHeader) (*model.AuthResponse, *api.LambdaError) {
expiration := time.Now().Add(time.Minute * 15)
atClaims := jwt.MapClaims{}
atClaims["exp"] = expiration.Unix()
atClaims["authenticated"] = "true" // Make this a string for authorization rules in dgraph
user, err := ... // Query the user
if err != nil {
return nil, &api.LambdaError{Underlying: err, Status: api.NOT_FOUND}
}
token, err := at.SignedString([]byte("secret"))
if err != nil {
return nil, &api.LambdaError{Underlying: err, Status: api.INTERNAL_ERROR}
}
return &model.AuthResponse{User: user, Token: token, Expiration: &expiration}, nil
}
This is quickly copied together, there might be some errors, but it should be enough to get going.