Skip to content

Commit 89f6338

Browse files
authored
feat: Adding example for using public OAuth (#769)
* Adding example for using public OAuth
1 parent 13d16a3 commit 89f6338

File tree

3 files changed

+31
-2
lines changed

3 files changed

+31
-2
lines changed

README.md

+5-1
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,12 @@ var message = MessageResource.Create(
7272
);
7373
Console.WriteLine(message.Sid);
7474
```
75+
## OAuth Feature for Twilio APIs
76+
We are introducing Client Credentials Flow-based OAuth 2.0 authentication. This feature is currently in beta and its implementation is subject to change.
7577

76-
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)
78+
API examples [here](https://github.com/twilio/twilio-csharp/blob/main/examples/PublicOAuthAuthentication.md)
79+
80+
Organisation API examples [here](https://github.com/twilio/twilio-csharp/blob/main/examples/BearerTokenAuthentication.md)
7781

7882
## Specify Region and/or Edge
7983

examples/BearerTokenAuthentication.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ class Program
1313
static void Main(string[] args)
1414
{
1515

16-
CredentialProvider credentialProvider = new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
16+
CredentialProvider credentialProvider = new OrgsClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
1717
TwilioClient.Init(credentialProvider);
1818

1919
Twilio.Base.ResourceSet<Twilio.Rest.PreviewIam.Organizations.AccountResource> accountList = null;

examples/PublicOAuthAuthentication.md

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
```csharp
2+
using Twilio;
3+
using Twilio.Credential;
4+
using Twilio.Rest.Api.V2010.Account;
5+
6+
//Find client id, client secret of the OAuth App
7+
//Message sid in this example is the sid of any previously sent message
8+
class Program
9+
{
10+
static void Main(string[] args)
11+
{
12+
CredentialProvider credentialProvider = new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET);
13+
TwilioClient.Init(credentialProvider, ACCOUNT_SID);
14+
15+
/*
16+
* Or use the following if accountSid is not required as a path parameter for an API or when setting accountSid in the API.
17+
TwilioClient.init(new ClientCredentialProvider(CLIENT_ID, CLIENT_SECRET));
18+
*/
19+
20+
FetchMessageOptions fm = new FetchMessageOptions(MESSAGE_SID);
21+
MessageResource m = MessageResource.Fetch(fm);
22+
Console.WriteLine(m.Body);
23+
}
24+
}
25+
```

0 commit comments

Comments
 (0)