Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion internal/services/dex_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (
"fmt"

"github.com/DIMO-Network/shared/privileges"
"github.com/DIMO-Network/token-exchange-api/pkg/tokenclaims"
dgrpc "github.com/dexidp/dex/api/v2"
"github.com/ethereum/go-ethereum/common"
"github.com/rs/zerolog"
Expand Down Expand Up @@ -48,7 +49,7 @@ func (d *DexClient) SignPrivilegePayload(ctx context.Context, req PrivilegeToken
privs[i] = privileges.Privilege(iD)
}

cc := CustomClaims{
cc := tokenclaims.CustomClaims{
ContractAddress: common.HexToAddress(req.NFTContractAddress),
TokenID: req.TokenID,
PrivilegeIDs: privs,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
package services
// Package tokenclaims provides a custom JWT token for token-exchange.
package tokenclaims

import (
"fmt"
Expand All @@ -10,17 +11,20 @@ import (
"google.golang.org/protobuf/types/known/structpb"
)

// CustomClaims is the custom claims for token-exchange related information.
type CustomClaims struct {
ContractAddress common.Address `json:"contract_address"`
TokenID string `json:"token_id"`
PrivilegeIDs []privileges.Privilege `json:"privilege_ids"`
}

// Token is a JWT token created by token-exchange.
type Token struct {
jwt.RegisteredClaims
CustomClaims
}

// Proto converts the CustomClaims to a protobuf struct.
func (c *CustomClaims) Proto() (*structpb.Struct, error) {
ap := make([]any, len(c.PrivilegeIDs))

Expand All @@ -37,7 +41,7 @@ func (c *CustomClaims) Proto() (*structpb.Struct, error) {
)
}

// Conflicts with the field, whoops.
// Sub returns the subject of the token.
func (c *CustomClaims) Sub() string {
return fmt.Sprintf("%s/%s", c.ContractAddress, c.TokenID)
}
Loading