Skip to content

Commit

Permalink
RC
Browse files Browse the repository at this point in the history
  • Loading branch information
Jaskaranbir committed Oct 2, 2018
1 parent a0f68c0 commit a96a9ae
Show file tree
Hide file tree
Showing 18 changed files with 691 additions and 661 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
KAFKA_BROKERS=kafka:9092

KAFKA_CONSUMER_GROUP_LOGIN=auth.login.consumergroup
KAFKA_CONSUMER_TOPIC_LOGIN=auth.login.response
KAFKA_PRODUCER_TOPIC_LOGIN=auth.login.request

Expand Down
2 changes: 1 addition & 1 deletion gql/resolver/accesstoken.go
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ var AccessTokenResolver = func(params graphql.ResolveParams) (interface{}, error
err = errors.Wrap(err, "Error renewing AccessToken")
return nil, err
}
return &model.AuthResponse{
return &model.AuthTokens{
AccessToken: at,
}, nil
}
211 changes: 0 additions & 211 deletions gql/resolver/authhandler.go

This file was deleted.

55 changes: 55 additions & 0 deletions gql/resolver/authhandler_util.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
package resolver

import (
"time"

"github.com/TerrexTech/go-apigateway/gwerrors"

"github.com/TerrexTech/go-apigateway/auth"
"github.com/TerrexTech/go-apigateway/model"
"github.com/pkg/errors"
)

// authResponse is the GraphQL response on successful authentication.
type authResponse struct {
tokens *model.AuthTokens
err *gwerrors.KRError
}

func genAccessToken(user *model.User) (*model.AccessToken, error) {
accessExp := 15 * time.Minute
claims := &model.Claims{
Role: user.Role,
Sub: user.UUID,
FirstName: user.FirstName,
LastName: user.LastName,
}
accessToken, err := model.NewAccessToken(accessExp, claims)
if err != nil {
err = errors.Wrap(err, "LoginResponseHandler: Error generating Access-Token")
return nil, err
}

return accessToken, nil
}

func genRefreshToken(ts auth.TokenStoreI, user *model.User) (*model.RefreshToken, error) {
refreshExp := (24 * 7) * time.Hour
refreshToken, err := model.NewRefreshToken(refreshExp, user.UUID)
if err != nil {
err = errors.Wrap(err, "Error generating Refresh-Token")
return nil, err
}
err = ts.Set(refreshToken)
// We continue executing the code even if storing refresh-token fails since other parts
// of application might still be accessible.
if err != nil {
err = errors.Wrapf(
err,
"Error storing RefreshToken in TokenStorage for UserID: %s", user.UUID,
)
return nil, err
}

return refreshToken, nil
}
Loading

0 comments on commit a96a9ae

Please sign in to comment.