Skip to content

Commit

Permalink
feat: Add SUB to JWT claim Okta
Browse files Browse the repository at this point in the history
  • Loading branch information
sbp-bvanb committed Dec 27, 2024
1 parent c6d3dd5 commit c44e412
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
1 change: 1 addition & 0 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ jobs:
build-args:
- mcvs-integrationtest-services
- mcvs-stub-server
- oktamock
runs-on: ubuntu-22.04
steps:
- uses: actions/[email protected]
Expand Down
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,5 @@
.task
.vscode
coverage.html
functioncoverage.out
profile.cov
1 change: 1 addition & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,5 @@ COPY --from=builder /etc/passwd /etc/passwd
COPY --from=builder /etc/ssl/certs/ca-certificates.crt /etc/ssl/certs/
COPY --from=builder /usr/share/zoneinfo /usr/share/zoneinfo
USER ${APPLICATION}
EXPOSE 8080
ENTRYPOINT ["/app/main"]
15 changes: 9 additions & 6 deletions cmd/oktamock/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ type JWTConfig struct {
Issuer string `env:"ISSUER" envDefault:"http://localhost:8080"`
KID string `env:"KID" envDefault:"mock-kid"`
SigningMethod SigningMethod `env:"SIGNING_METHOD" envDefault:"RS256"`
Sub string `env:"SUB" envDefault:""`
}

// NewConfig returns the config.
Expand Down Expand Up @@ -109,9 +110,9 @@ func main() {
// OktaMockServer represents a mock Okta server which can be used to create and validate JWT tokens.
// Serves as a subtitute for using an actual Okta Server.
type OktaMockServer struct {
audience, issuer string
expiration time.Duration
groups []string
audience, issuer, sub string
expiration time.Duration
groups []string

privKey *rsa.PrivateKey
jwkKey jwk.Key
Expand All @@ -133,11 +134,12 @@ func (o *OktaMockServer) handleGetValidJWT(w http.ResponseWriter, r *http.Reques
now := time.Now()
claims := jwt.MapClaims{
"aud": o.audience,
"iss": o.issuer,
"iat": now.Unix(),
"exp": now.Add(o.expiration).Unix(),
"nbf": now.AddDate(0, 0, -1).Unix(),
"Groups": o.groups,
"iat": now.Unix(),
"iss": o.issuer,
"nbf": now.AddDate(0, 0, -1).Unix(),
"sub": o.sub,
}

// Add custom claims
Expand Down Expand Up @@ -220,6 +222,7 @@ func NewOktaMockServer(cfg *Config) (*OktaMockServer, error) {
issuer: cfg.JWTConfig.Issuer,
jwkKey: jwkKey,
privKey: privKeyRSA,
sub: cfg.JWTConfig.Sub,
}, nil
}

Expand Down

0 comments on commit c44e412

Please sign in to comment.