Skip to content

Commit

Permalink
feat: Adding example for using public OAuth (#769)
Browse files Browse the repository at this point in the history
* Adding example for using public OAuth
  • Loading branch information
AsabuHere authored Nov 14, 2024
1 parent 13d16a3 commit 89f6338
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 2 deletions.
6 changes: 5 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,12 @@ var message = MessageResource.Create(
);
Console.WriteLine(message.Sid);
```
## OAuth Feature for Twilio APIs
We are introducing Client Credentials Flow-based OAuth 2.0 authentication. This feature is currently in beta and its implementation is subject to change.

Examples on how to make rest calls with bearer token authentication is added [here](https://github.com/twilio/twilio-csharp/blob/orgs_api_uptake/examples/BearerTokenAuthentication.md)
API examples [here](https://github.com/twilio/twilio-csharp/blob/main/examples/PublicOAuthAuthentication.md)

Organisation API examples [here](https://github.com/twilio/twilio-csharp/blob/main/examples/BearerTokenAuthentication.md)

## Specify Region and/or Edge

Expand Down
2 changes: 1 addition & 1 deletion examples/BearerTokenAuthentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Program
static void Main(string[] args)
{

CredentialProvider credentialProvider = new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
CredentialProvider credentialProvider = new OrgsClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
TwilioClient.Init(credentialProvider);

Twilio.Base.ResourceSet<Twilio.Rest.PreviewIam.Organizations.AccountResource> accountList = null;
Expand Down
25 changes: 25 additions & 0 deletions examples/PublicOAuthAuthentication.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
```csharp
using Twilio;
using Twilio.Credential;
using Twilio.Rest.Api.V2010.Account;

//Find client id, client secret of the OAuth App
//Message sid in this example is the sid of any previously sent message
class Program
{
static void Main(string[] args)
{
CredentialProvider credentialProvider = new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
TwilioClient.Init(credentialProvider, ACCOUNT_SID);

/*
* Or use the following if accountSid is not required as a path parameter for an API or when setting accountSid in the API.
TwilioClient.init(new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET));
*/

FetchMessageOptions fm = new FetchMessageOptions(MESSAGE_SID);
MessageResource m = MessageResource.Fetch(fm);
Console.WriteLine(m.Body);
}
}
```

0 comments on commit 89f6338

Please sign in to comment.