diff --git a/infra/traq/group.go b/infra/traq/group.go index 9b05945c..21c3b126 100644 --- a/infra/traq/group.go +++ b/infra/traq/group.go @@ -11,7 +11,7 @@ import ( func (repo *TraQRepository) GetGroup(groupID uuid.UUID) (*traq.UserGroup, error) { ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, repo.ServerAccessToken) - apiClient := traq.NewAPIClient(traqAPIConfig) + apiClient := traq.NewAPIClient(traq.NewConfiguration()) // TODO: 一定期間キャッシュする group, resp, err := apiClient.GroupApi.GetUserGroup(ctx, groupID.String()).Execute() if err != nil { @@ -26,7 +26,7 @@ func (repo *TraQRepository) GetGroup(groupID uuid.UUID) (*traq.UserGroup, error) func (repo *TraQRepository) GetAllGroups() ([]traq.UserGroup, error) { ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, repo.ServerAccessToken) - apiClient := traq.NewAPIClient(traqAPIConfig) + apiClient := traq.NewAPIClient(traq.NewConfiguration()) // TODO: 一定期間キャッシュする groups, resp, err := apiClient.GroupApi.GetUserGroups(ctx).Execute() if err != nil { @@ -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(traq.NewConfiguration()) user, resp, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute() if err != nil { return nil, err diff --git a/infra/traq/traq.go b/infra/traq/traq.go index 7c5a6405..ab5bc5b4 100644 --- a/infra/traq/traq.go +++ b/infra/traq/traq.go @@ -7,7 +7,6 @@ import ( "errors" "net/url" - "github.com/traPtitech/go-traq" "github.com/traPtitech/knoQ/utils/random" "golang.org/x/oauth2" ) @@ -19,19 +18,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) { codeVerifier = random.AlphaNumeric(43, true) result := sha256.Sum256([]byte(codeVerifier)) @@ -66,11 +52,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 -} diff --git a/infra/traq/user.go b/infra/traq/user.go index f8c87e0f..1bd4ff9a 100644 --- a/infra/traq/user.go +++ b/infra/traq/user.go @@ -10,7 +10,7 @@ import ( func (repo *TraQRepository) GetUser(userID uuid.UUID) (*traq.User, error) { ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, repo.ServerAccessToken) - apiClient := traq.NewAPIClient(traqAPIConfig) + apiClient := traq.NewAPIClient(traq.NewConfiguration()) // TODO: 一定期間キャッシュする userDetail, resp, err := apiClient.UserApi.GetUser(ctx, userID.String()).Execute() if err != nil { @@ -34,7 +34,7 @@ func (repo *TraQRepository) GetUser(userID uuid.UUID) (*traq.User, error) { func (repo *TraQRepository) GetUsers(includeSuspended bool) ([]traq.User, error) { ctx := context.WithValue(context.TODO(), traq.ContextAccessToken, repo.ServerAccessToken) - apiClient := traq.NewAPIClient(traqAPIConfig) + apiClient := traq.NewAPIClient(traq.NewConfiguration()) // TODO: 一定期間キャッシュする users, resp, err := apiClient.UserApi.GetUsers(ctx).IncludeSuspended(includeSuspended).Execute() if err != nil { @@ -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(traq.NewConfiguration()) userDetail, resp, err := apiClient.MeApi.GetMe(ctx).Execute() if err != nil { return nil, err