-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a0f68c0
commit a96a9ae
Showing
18 changed files
with
691 additions
and
661 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
Oops, something went wrong.