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
1414var jwtParser = new (jwt.Parser )
@@ -69,8 +69,8 @@ type OAuthCredentials struct {
6969
7070// APIOAuth handles OAuth authentication for the Twilio API.
7171type 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.
8181func 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