Skip to content

Commit

Permalink
🎨 remove NewOAuthAPI function, remove HTTPCLient field's assignment
Browse files Browse the repository at this point in the history
  • Loading branch information
iChemy committed Aug 26, 2024
1 parent c6dad52 commit 0a1a579
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 23 deletions.
4 changes: 2 additions & 2 deletions infra/traq/group.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ func (repo *TraQRepository) GetAllGroups() ([]traq.UserGroup, error) {
}

func (repo *TraQRepository) GetUserBelongingGroupIDs(token *oauth2.Token, userID uuid.UUID) ([]uuid.UUID, error) {
ctx := context.TODO()
apiClient := NewOauth2APIClient(ctx, token)
ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, token.AccessToken)
apiClient := traq.NewAPIClient(traqAPIConfig)
user, resp, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute()
if err != nil {
return nil, err
Expand Down
19 changes: 0 additions & 19 deletions infra/traq/traq.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,6 @@ type TraQRepository struct {
ServerAccessToken string
}

var TraQDefaultConfig = &oauth2.Config{
ClientID: "something",
ClientSecret: "any",
RedirectURL: "foo",
Scopes: []string{"read", "write", "manage_bot"},
Endpoint: oauth2.Endpoint{
AuthURL: "https://q.trap.jp/api/v3/oauth2/authorize",
TokenURL: "https://q.trap.jp/api/v3/oauth2/token",
},
}

var traqAPIConfig = traq.NewConfiguration()

func newPKCE() (pkceOptions []oauth2.AuthCodeOption, codeVerifier string) {
Expand Down Expand Up @@ -66,11 +55,3 @@ func (repo *TraQRepository) GetOAuthToken(query, state, codeVerifier string) (*o
option := oauth2.SetAuthURLParam("code_verifier", codeVerifier)
return repo.Config.Exchange(ctx, code, option)
}

func NewOauth2APIClient(ctx context.Context, token *oauth2.Token) *traq.APIClient {
traqconf := traqAPIConfig
conf := TraQDefaultConfig
traqconf.HTTPClient = conf.Client(ctx, token)
apiClient := traq.NewAPIClient(traqconf)
return apiClient
}
4 changes: 2 additions & 2 deletions infra/traq/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,8 @@ func (repo *TraQRepository) GetUsers(includeSuspended bool) ([]traq.User, error)
}

func (repo *TraQRepository) GetUserMe(token *oauth2.Token) (*traq.User, error) {
ctx := context.TODO()
apiClient := NewOauth2APIClient(ctx, token)
ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, token.AccessToken)
apiClient := traq.NewAPIClient(traqAPIConfig)
userDetail, resp, err := apiClient.MeApi.GetMe(ctx).Execute()
if err != nil {
return nil, err
Expand Down

0 comments on commit 0a1a579

Please sign in to comment.