Skip to content

Commit cf9e4af

Browse files
chore: change oauth token endpoint (#302)
* chore: change oauth token endpoint * chore: update cluster tests
1 parent df31f57 commit cf9e4af

File tree

2 files changed

+12
-12
lines changed

2 files changed

+12
-12
lines changed

cluster_test.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ import (
1515
EventsV1 "github.com/twilio/twilio-go/rest/events/v1"
1616

1717
"github.com/stretchr/testify/assert"
18-
IamV1 "github.com/twilio/twilio-go/rest/iam/v1"
18+
OauthV2 "github.com/twilio/twilio-go/rest/oauth/v2"
1919
)
2020

2121
var from string
@@ -216,7 +216,7 @@ func TestTokenAuth_FetchToken(t *testing.T) {
216216
var clientId = os.Getenv("TWILIO_CLIENT_ID")
217217
var clientSecret = os.Getenv("TWILIO_CLIENT_SECRET")
218218

219-
params := &IamV1.CreateTokenParams{
219+
params := &OauthV2.CreateOauth2TokenParams{
220220
GrantType: &grantType,
221221
ClientId: &clientId,
222222
ClientSecret: &clientSecret,
@@ -227,7 +227,7 @@ func TestTokenAuth_FetchToken(t *testing.T) {
227227
Scope: nil,
228228
}
229229

230-
resp, err := testClient.IamV1.CreateToken(params)
230+
resp, err := testClient.OauthV2.CreateOauth2Token(params)
231231
assert.Nil(t, err)
232232
assert.NotNil(t, resp)
233233
}
@@ -237,13 +237,13 @@ func TestTokenAuthFetchTokenException(t *testing.T) {
237237
var clientId = os.Getenv("TWILIO_CLIENT_ID")
238238
var clientSecret = os.Getenv("TWILIO_CLIENT_SECRET") + "invalid"
239239

240-
params := &IamV1.CreateTokenParams{
240+
params := &OauthV2.CreateOauth2TokenParams{
241241
GrantType: &grantType,
242242
ClientId: &clientId,
243243
ClientSecret: &clientSecret,
244244
}
245245

246-
resp, err := testClient.IamV1.CreateToken(params)
246+
resp, err := testClient.OauthV2.CreateOauth2Token(params)
247247
assert.NotNil(t, 403, err.(*client.TwilioRestError).Status)
248248
assert.Nil(t, resp)
249249
}

oauth.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"github.com/golang-jwt/jwt/v5"
99

1010
"github.com/twilio/twilio-go/client"
11-
iam "github.com/twilio/twilio-go/rest/iam/v1"
11+
oauth "github.com/twilio/twilio-go/rest/oauth/v2"
1212
)
1313

1414
var jwtParser = new(jwt.Parser)
@@ -69,8 +69,8 @@ type OAuthCredentials struct {
6969

7070
// APIOAuth handles OAuth authentication for the Twilio API.
7171
type APIOAuth struct {
72-
// iamService is the service used to interact with the IAM API.
73-
iamService *iam.ApiService
72+
// oauthService is the service used to interact with the OAuth API.
73+
oauthService *oauth.ApiService
7474
// creds holds the necessary credentials for OAuth authentication.
7575
creds *OAuthCredentials
7676
// tokenAuth *TokenAuth
@@ -79,7 +79,7 @@ type APIOAuth struct {
7979

8080
// NewAPIOAuth creates a new APIOAuth instance with the provided request handler and credentials.
8181
func NewAPIOAuth(c *client.RequestHandler, creds *OAuthCredentials) *APIOAuth {
82-
a := &APIOAuth{iamService: iam.NewApiService(c), creds: creds}
82+
a := &APIOAuth{oauthService: oauth.NewApiService(c), creds: creds}
8383
return a
8484
}
8585

@@ -95,12 +95,12 @@ func (a *APIOAuth) GetAccessToken(ctx context.Context) (string, error) {
9595
if a.tokenAuth.Token != "" && !expired {
9696
return a.tokenAuth.Token, nil
9797
}
98-
params := &iam.CreateTokenParams{}
98+
params := &oauth.CreateOauth2TokenParams{}
9999
params.SetGrantType(a.creds.GrantType).
100100
SetClientId(a.creds.ClientId).
101101
SetClientSecret(a.creds.ClientSecret)
102-
a.iamService.RequestHandler().Client.SetOauth(nil) // set oauth to nil to make no-auth request
103-
token, err := a.iamService.CreateToken(params)
102+
a.oauthService.RequestHandler().Client.SetOauth(nil) // set oauth to nil to make no-auth request
103+
token, err := a.oauthService.CreateOauth2Token(params)
104104
if err == nil {
105105
a.tokenAuth = TokenAuth{
106106
Token: *token.AccessToken,

0 commit comments

Comments
 (0)