Authentication
The WellViaSDK authenticates itself with the Recuro Health API using the same OAuth2 implementation covered in the Authentication API guide. If you are not yet familiar with this, we recommend you start there.
Required Keys
Prior to beginning, you will need your SubscriptionKey, ClientId, and ClientSecret.
Configuration
When initializing any Service Client, you will need to provide a WellViaClientConfig. Most implementations do not require anything beyond specifying your SubscriptionKey. All libraries can share the same configuration.
Example
using WellViaSDK.Core;
// Variables
var mySubscriptionKey = "your_subscription_key";
// Create Client Configuration
var config = new WellViaClientConfig(mySubscriptionKey);Credentials
All WellViaSDK libraries use the ClientCredentials to authenticate. These credentials are simply passed into the service client you are using.
Client Credentials (Service)
Create Credentials
To authenticate a service or application, we will need to create a Service Access Token.
Example
using WellViaSDK.Core;
// Variables
var myClientId = "your_client_id";
var myClientSecret = "your_client_secret";
// Create Core Service Client
var coreClient = WellViaCoreServiceClient(config);
// Create the ClientCredentials
var creds = coreClient.CreateClientCredentials(myClientId, myClientSecret);Handling Access Token Limits
When you need to authenticate as an application or service (not a user), we need to ensure we account for the Access Token expiration policy. Expanding on the above code, we have included a simple outline to account for this requirement.
Example
using WellViaSDK.Core;
using WellViaSDK.Event;
// Variables
var myClientId = "your_client_id";
var myClientSecret = "your_client_secret";
// Create Core Service Client
var coreClient = WellViaCoreServiceClient(config);
// Get existing access token (if one exists) from your secure storage
var wvToken = GetStoredTokenForMyApp();
// Create ClientCredentials from the AccessToken
var creds = new ClientCredentials(wvToken);
// Check that the access token exists, is valid, has not expired, or will not expire in the next 120 seconds
if (!creds.IsValid()) {
// Create new ClientCredentials
creds = coreClient.CreateClientCredentials(myClientId, myClientSecret);
// Update your secure storage with new access token
UpdateStoredTokenForMyApp(creds.AccessToken);
}
// Use config and creds to establish any client service
var evntClient = WellViaEventServiceClient(config, creds);Client Credentials (User)
Create Credentials
To authenticate an application or service on behalf of a user, we will need to create a User Access Token.
Example
using WellViaSDK.Core;
using WellViaSDK.Member;
// Variables
var myClientId = "your_client_id";
var myClientSecret = "your_client_secret";
var userId = "ABC123"; // WellViaMemberID or ClientMemberID
var userFirstName = "John";
var userLastName = "Doe";
var userDateOfBirth = new DateTime.Parse("03/15/1970");
// Create Core Service Client
var coreClient = WellViaCoreServiceClient(config);
// Create the ClientCredentials
var creds = coreClient.CreateClientCredentials(myClientId, myClientSecret, userId, userFirstName, userLastName, userDateOfBirth);
// Use config and creds to establish any client service
var mbrClient = WellViaMemberServiceClient(config, creds);Updated 7 months ago
