Skip to content

Conversation

@toanvc
Copy link

@toanvc toanvc commented Aug 9, 2023

Why?

A few months back I created an issue #239, that we need to use Oauth with bearer authentication in our project. I haven't heard any responses yet from the issue I created. So we went ahead and implemented ourself.

What

In this MR, I added renew middleware from mappersmith project https://github.com/tulios/mappersmith#-renew. This will help to renew the token if it's expired. I also added a way that we can set the refreshThresholdMs to auto refresh the token if it's expired by our timer.

Example

// We have a refreshToken function to get the token from our service
export async function refreshToken(authHost: string, clientId: string, clientSecret: string): Promise<string> {
  /// creating your data and axiosConfig
  const response = await axios.post<PostObject>(authHost, data, axiosConfig)
  return `Bearer ${response.data.access_token}`
}

// And add it into the params:
new SchemaRegistry({
      host: host,
      accessTokenParams: {
        clientCredentials: {
          clientId: '',
          clientSecret: ''
        },
        authHost: '',
        refreshToken: refreshToken
      }
    })

@toanvc toanvc changed the title Adding AccessTokenMiddleware to support bearer token authentication Adding AccessTokenMiddleware to support oauth Sep 18, 2023
@kriskw1999 kriskw1999 self-requested a review December 21, 2024 10:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants