Skip to content

Commit

Permalink
Docs update for bearer token authentication and endpoints with no auth
Browse files Browse the repository at this point in the history
  • Loading branch information
AsabuHere committed Jun 22, 2024
1 parent b5d7622 commit 1de543c
Showing 1 changed file with 40 additions and 0 deletions.
40 changes: 40 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,46 @@ public class Example {
}
}
```
### Initialize the client when endpoints does not use basic authentication
The above example shows how to initialize the client in case the endpoints use basic authentication. When the endpoint does not require any authentication, use TwilioNoAuth client instead.
Also there are endpoints like Organization domain which uses bearer token authentication. Custom Clients needs to be used in such cases and initialize them with the values required for access token generation

```java
import com.twilio.TwilioOrgsTokenAuth;
import com.twilio.exception.AuthenticationException;

public class Example {

private static final String GRANT_TYPE = "grant_type_to_be_used";
private static final String CLIENT_SID =
"client_id_of_the_organization";
private static final String CLIENT_SECRET = "client_secret_of_organization";

public static void main(String[] args) throws AuthenticationException {
TwilioOrgsTokenAuth.init(GRANT_TYPE, CLIENT_SID, CLIENT_SECRET);
}
}
```

To bypass the initialization step you can also use a custom token manager implementation. Token manager class should implement the Token interface and call a token generation endpoint of your choice. Here is a sample code.

```java
import com.twilio.TwilioOrgsTokenAuth;
import com.twilio.exception.AuthenticationException;

public class Example {

private static final String GRANT_TYPE = "grant_type_to_be_used";
private static final String CLIENT_SID =
"client_id_of_the_organization";
private static final String CLIENT_SECRET = "client_secret_of_organization";

public static void main(String[] args) throws AuthenticationException {
TwilioOrgsTokenAuth.setTokenManager(new CustomTokenManagerImpl(GRANT_TYPE, CLIENT_SID, CLIENT_SECRET));
}
}
```
Detailed example [here](https://github.com/twilio/twilio-java/tree/main/examples)

### Environment Variables

Expand Down

0 comments on commit 1de543c

Please sign in to comment.