Skip to content

Commit

Permalink
Make example work
Browse files Browse the repository at this point in the history
  • Loading branch information
raphael committed Nov 21, 2024
1 parent 4c326e3 commit 81d4922
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 10 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,4 @@ tus/upload-cli
upload_download/upload_download
upload_download/upload_download-cli
basic/cmd/calc/calc
interceptors/cmd/example/example
8 changes: 6 additions & 2 deletions interceptors/example.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func NewExample() example.Service {

// GetRecord implements get_record.
func (s *examplesrvc) GetRecord(ctx context.Context, p *example.GetRecordPayload) (res *example.Record, err error) {
res = &example.Record{}
log.Printf(ctx, "example.get_record")
res = &example.Record{
TenantID: *p.TenantID,
RecordID: "123",
FullName: "John Doe",
}
log.Printf(ctx, "example.get_record: %v", p)
return
}
19 changes: 11 additions & 8 deletions interceptors/interceptors.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ type JWTTenantClaims struct {
}

func NewExampleInterceptors() example.ServerInterceptors {
return &Interceptors{}
return &Interceptors{
cache: make(map[string]any),
}
}

func (i *Interceptors) DecodeTenant(ctx context.Context, payload *example.DecodeTenantPayload, info *goa.InterceptorInfo, processor example.DecodeTenantProcessor) (any, error) {
Expand All @@ -31,13 +33,14 @@ func (i *Interceptors) DecodeTenant(ctx context.Context, payload *example.Decode
return nil, errors.New("invalid auth token")
}
token := auth[7:] // "Bearer "
var claims jwt.MapClaims
_, err := jwt.ParseWithClaims(token, &claims, func(token *jwt.Token) (interface{}, error) {
return []byte("tenantID"), nil
})
if err != nil {
return nil, err
}
claims := jwt.MapClaims{}
// _, err := jwt.ParseWithClaims(token, &claims, func(token *jwt.Token) (any, error) {
// return []byte("tenantID"), nil
// })
// if err != nil {
// return nil, err
// }
claims["tenantID"] = token
tenantID, ok := claims["tenantID"]
if !ok {
return nil, errors.New("missing tenantID in JWT")
Expand Down

0 comments on commit 81d4922

Please sign in to comment.