inloco / incognia-go

Go library for Incognia API
MIT License
5 stars 5 forks source link

refactor(credentials_manager): extract two different token providers #26

Closed lucasbarross closed 2 years ago

lucasbarross commented 2 years ago

This PR allows clients to choose which type of token providing method will be used by the SDK.

AutoRefreshTokenProvider will be used as a default.

ManualRefreshTokenProvider usage example:

tokenClient := incognia.NewTokenClient({clientId: ...., clientSecret:...})
tokenProvider := incognia.NewManualRefreshTokenProvider(tokenClient)
c := incognia.NewClient({tokenProvider: tokenProvider}

go func(i *incognia.Client) {
  for {
      accessToken := tokenProvider.Refresh()
      time.Sleep(time.Until(accessToken.GetExpiresAt()))
   }
}(c)
faustikle commented 2 years ago

You must read this: Receiver Type and try to avoid heap allocations and gc time in this project. I see a lot of pointers that should be just values.

faustikle commented 2 years ago

accessToken := tokenProvider.Refresh()

What should I do with accessToken?

lucasbarross commented 2 years ago

accessToken := tokenProvider.Refresh()

What should I do with accessToken?

@faustikle You should use the ExpiresAt information to schedule the next refresh. time.Sleep(time.Until(accessToken.GetExpiresAt()))