authlete / authlete-go

Authlete Library for Go
https://www.authlete.com/
Apache License 2.0
12 stars 4 forks source link

Add ctx context.Context to each API invocation method for context propagation #16

Open haton14 opened 6 months ago

haton14 commented 6 months ago

In Go, we use context.Context to propagate cancellations. For instance, in the calling chain below, if the communication is cut off from the OAuth client, the call to the Authlete API via the OAuth server will be cancelled. OAuth client => OAuth server => Authlete API

However, since there are users of the existing methods, maintaining compatibility is necessary. To address this, I propose to add it to the interface in the following manner:

https://github.com/authlete/authlete-go/blob/master/api/authlete_api.go#L21-L25

type AuthleteApi interface {
    Settings() *Settings
    Authorization(request *dto.AuthorizationRequest) (*dto.AuthorizationResponse, *AuthleteError)
    AuthorizationWithContext(ctx context.Context, request *dto.AuthorizationRequest) (*dto.AuthorizationResponse, *AuthleteError)
    AuthorizationFail(request *dto.AuthorizationFailRequest) (*dto.AuthorizationFailResponse, *AuthleteError)
    AuthorizationFailWithContext(ctx context.Context, request *dto.AuthorizationFailRequest) (*dto.AuthorizationFailResponse, *AuthleteError)
    ...

(translation by gpt-4)

hefa commented 6 months ago

Indeed this is a problem... Until this is addressed, I recommend using https://github.com/authlete/openapi-for-go which supports Context propagation.