Skip to content

OAuth token request fails when used inside Gin middleware with context cancellation #2

@francescobianco

Description

@francescobianco

OAuth token request fails when used inside Gin middleware with context cancellation

Description
When using the SDK inside a Gin middleware, token creation fails if the request context is cancelled early.

Code snippet

r := gin.Default()

r.Use(func(c *gin.Context) {
    oauthClient := client.NewOauthClient(user, apiKey, true)
    token, err := oauthClient.CreateToken(c.Request.Context(), []string{"scope"}, 3600)
    if err != nil {
        log.Println("token error:", err)
    }
    c.Next()
})

Observed behavior
context canceled error returned intermittently.

Expected behavior
Token generation should complete even if the HTTP request lifecycle ends.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions