From 73bbac1efe539ca8d39faf6382ebc33ba6eeadc3 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Fri, 26 Sep 2025 16:04:29 +0530 Subject: [PATCH 1/3] chore: change oauth token endpoint --- src/Twilio/Rest/Oauth/V2/TokenOptions.cs | 12 ++++++++++-- src/Twilio/Rest/Oauth/V2/TokenResource.cs | 12 ++++++------ 2 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Twilio/Rest/Oauth/V2/TokenOptions.cs b/src/Twilio/Rest/Oauth/V2/TokenOptions.cs index b393b4186..604a93cb8 100644 --- a/src/Twilio/Rest/Oauth/V2/TokenOptions.cs +++ b/src/Twilio/Rest/Oauth/V2/TokenOptions.cs @@ -29,10 +29,10 @@ public class CreateTokenOptions : IOptions { /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. - public string GrantType { get; set; } + public string GrantType { get; } /// A 34 character string that uniquely identifies this OAuth App. - public string ClientId { get; set; } + public string ClientId { get; } /// The credential for confidential OAuth App. public string ClientSecret { get; set; } @@ -53,6 +53,14 @@ public class CreateTokenOptions : IOptions public string Scope { get; set; } + /// Construct a new CreateOauth2TokenOptions + /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. + /// A 34 character string that uniquely identifies this OAuth App. + public CreateTokenOptions(string grantType, string clientId) + { + GrantType = grantType; + ClientId = clientId; + } /// Generate the necessary parameters diff --git a/src/Twilio/Rest/Oauth/V2/TokenResource.cs b/src/Twilio/Rest/Oauth/V2/TokenResource.cs index bdfe34d63..288faab1c 100644 --- a/src/Twilio/Rest/Oauth/V2/TokenResource.cs +++ b/src/Twilio/Rest/Oauth/V2/TokenResource.cs @@ -86,8 +86,8 @@ public static async System.Threading.Tasks.Task CreateAsync(Creat /// Client to make requests to Twilio /// A single instance of Token public static TokenResource Create( - string grantType = null, - string clientId = null, + string grantType, + string clientId, string clientSecret = null, string code = null, string redirectUri = null, @@ -96,7 +96,7 @@ public static TokenResource Create( string scope = null, ITwilioRestClient client = null) { - var options = new CreateTokenOptions(){ GrantType = grantType, ClientId = clientId, ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; + var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; return Create(options, client); } @@ -113,8 +113,8 @@ public static TokenResource Create( /// Client to make requests to Twilio /// Task that resolves to A single instance of Token public static async System.Threading.Tasks.Task CreateAsync( - string grantType = null, - string clientId = null, + string grantType, + string clientId, string clientSecret = null, string code = null, string redirectUri = null, @@ -123,7 +123,7 @@ public static async System.Threading.Tasks.Task CreateAsync( string scope = null, ITwilioRestClient client = null) { - var options = new CreateTokenOptions(){ GrantType = grantType, ClientId = clientId, ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; + var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; return await CreateAsync(options, client); } #endif From 719493744048b3c1b3ad7d1e20b3f0903fcc14e6 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Fri, 26 Sep 2025 16:12:27 +0530 Subject: [PATCH 2/3] chore: change oauth token endpoint --- src/Twilio/Http/BearerToken/ApiTokenManager.cs | 2 +- src/Twilio/Http/BearerToken/OrgsTokenManager.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Twilio/Http/BearerToken/ApiTokenManager.cs b/src/Twilio/Http/BearerToken/ApiTokenManager.cs index 2d36e4a99..4db3ba12f 100644 --- a/src/Twilio/Http/BearerToken/ApiTokenManager.cs +++ b/src/Twilio/Http/BearerToken/ApiTokenManager.cs @@ -1,4 +1,4 @@ -using Twilio.Rest.Iam.V1; +using Twilio.Rest.Oauth.V2; using Twilio.Exceptions; using System; using Twilio.Annotations; diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 716ac7bbc..46bcd65f1 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -1,4 +1,4 @@ -using Twilio.Rest.Iam.V1; +using Twilio.Rest.Oauth.V2; using Twilio.Exceptions; using System; using Twilio.Annotations; From ab147ae5f665a40ed0f83424667d47222bbb2f38 Mon Sep 17 00:00:00 2001 From: Shubham Tiwari Date: Mon, 29 Sep 2025 12:10:05 +0530 Subject: [PATCH 3/3] chore: change fetchAccessToken() with optional params --- src/Twilio/Http/BearerToken/ApiTokenManager.cs | 4 +++- src/Twilio/Http/BearerToken/OrgsTokenManager.cs | 4 +++- src/Twilio/Rest/Oauth/V2/TokenOptions.cs | 12 ++---------- src/Twilio/Rest/Oauth/V2/TokenResource.cs | 12 ++++++------ 4 files changed, 14 insertions(+), 18 deletions(-) diff --git a/src/Twilio/Http/BearerToken/ApiTokenManager.cs b/src/Twilio/Http/BearerToken/ApiTokenManager.cs index 4db3ba12f..e6ee063bc 100644 --- a/src/Twilio/Http/BearerToken/ApiTokenManager.cs +++ b/src/Twilio/Http/BearerToken/ApiTokenManager.cs @@ -43,7 +43,9 @@ public ApiTokenManager( } public string fetchAccessToken(){ - CreateTokenOptions createTokenOptions = new CreateTokenOptions(GrantType, ClientId); + CreateTokenOptions createTokenOptions = new CreateTokenOptions(); + if(GrantType != null){ createTokenOptions.GrantType = GrantType;} + if(ClientId != null){ createTokenOptions.ClientId = ClientId;} if(ClientSecret != null){ createTokenOptions.ClientSecret = ClientSecret;} if(Code != null){ createTokenOptions.Code = Code; } if(RedirectUri != null){ createTokenOptions.RedirectUri = RedirectUri; } diff --git a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs index 46bcd65f1..399d426db 100644 --- a/src/Twilio/Http/BearerToken/OrgsTokenManager.cs +++ b/src/Twilio/Http/BearerToken/OrgsTokenManager.cs @@ -42,7 +42,9 @@ public OrgsTokenManager( } public string fetchAccessToken(){ - CreateTokenOptions createTokenOptions = new CreateTokenOptions(GrantType, ClientId); + CreateTokenOptions createTokenOptions = new CreateTokenOptions(); + if(GrantType != null){ createTokenOptions.GrantType = GrantType;} + if(ClientId != null){ createTokenOptions.ClientId = ClientId;} if(ClientSecret != null){ createTokenOptions.ClientSecret = ClientSecret;} if(Code != null){ createTokenOptions.Code = Code; } if(RedirectUri != null){ createTokenOptions.RedirectUri = RedirectUri; } diff --git a/src/Twilio/Rest/Oauth/V2/TokenOptions.cs b/src/Twilio/Rest/Oauth/V2/TokenOptions.cs index 604a93cb8..b393b4186 100644 --- a/src/Twilio/Rest/Oauth/V2/TokenOptions.cs +++ b/src/Twilio/Rest/Oauth/V2/TokenOptions.cs @@ -29,10 +29,10 @@ public class CreateTokenOptions : IOptions { /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. - public string GrantType { get; } + public string GrantType { get; set; } /// A 34 character string that uniquely identifies this OAuth App. - public string ClientId { get; } + public string ClientId { get; set; } /// The credential for confidential OAuth App. public string ClientSecret { get; set; } @@ -53,14 +53,6 @@ public class CreateTokenOptions : IOptions public string Scope { get; set; } - /// Construct a new CreateOauth2TokenOptions - /// Grant type is a credential representing resource owner's authorization which can be used by client to obtain access token. - /// A 34 character string that uniquely identifies this OAuth App. - public CreateTokenOptions(string grantType, string clientId) - { - GrantType = grantType; - ClientId = clientId; - } /// Generate the necessary parameters diff --git a/src/Twilio/Rest/Oauth/V2/TokenResource.cs b/src/Twilio/Rest/Oauth/V2/TokenResource.cs index 288faab1c..bdfe34d63 100644 --- a/src/Twilio/Rest/Oauth/V2/TokenResource.cs +++ b/src/Twilio/Rest/Oauth/V2/TokenResource.cs @@ -86,8 +86,8 @@ public static async System.Threading.Tasks.Task CreateAsync(Creat /// Client to make requests to Twilio /// A single instance of Token public static TokenResource Create( - string grantType, - string clientId, + string grantType = null, + string clientId = null, string clientSecret = null, string code = null, string redirectUri = null, @@ -96,7 +96,7 @@ public static TokenResource Create( string scope = null, ITwilioRestClient client = null) { - var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; + var options = new CreateTokenOptions(){ GrantType = grantType, ClientId = clientId, ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; return Create(options, client); } @@ -113,8 +113,8 @@ public static TokenResource Create( /// Client to make requests to Twilio /// Task that resolves to A single instance of Token public static async System.Threading.Tasks.Task CreateAsync( - string grantType, - string clientId, + string grantType = null, + string clientId = null, string clientSecret = null, string code = null, string redirectUri = null, @@ -123,7 +123,7 @@ public static async System.Threading.Tasks.Task CreateAsync( string scope = null, ITwilioRestClient client = null) { - var options = new CreateTokenOptions(grantType, clientId){ ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; + var options = new CreateTokenOptions(){ GrantType = grantType, ClientId = clientId, ClientSecret = clientSecret, Code = code, RedirectUri = redirectUri, Audience = audience, RefreshToken = refreshToken, Scope = scope }; return await CreateAsync(options, client); } #endif