Skip to content

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

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.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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