You take your clientid and secret, and convert them to a base64string, put that in the header as bearer. grant_type is client_credentials, and you have to include a scope parm, like Patient_read
Here is my method in C#
public static async Task<string> getCernerToken(string scope)
{
if (string.IsNullOrEmpty(ClientId))
return "Missing ClientID";
if (string.IsNullOrEmpty(TenantId))
return "Missing TenantID";
if (string.IsNullOrEmpty(Secret))
return "Missing Secret";
if (string.IsNullOrEmpty(BaseAuthUrl))
return "Missing BaseAuth";
var token = string.Empty;
var clientSecretString = $"{ClientId}:{Secret}";
var convertedString = Convert.ToBase64String(Encoding.ASCII.GetBytes(clientSecretString));
var authUrl = $"{BaseAuthUrl}{TenantId}/protocols/oauth2/profiles/smart-v1/token";
var grantType = "client_credentials";
HttpResponseMessage res = new HttpResponseMessage();
using (var client = new HttpClient())
{
var builder = new UriBuilder(authUrl);
var url = builder.ToString();
client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", convertedString);
client.DefaultRequestHeaders.Add("Accept", "application/json");
// Fiddler or Wireshark
var data = new FormUrlEncodedContent(new Dictionary<string, string> { { "grant_type", grantType }, { "scope", scope } });
res = await client.PostAsync(authUrl, data);
}
var responseString = await res.Content.ReadAsStringAsync();
if (string.IsNullOrEmpty(responseString))
return string.Empty;
var json = JObject.Parse(responseString);
if (json != null)
token = json["access_token"]?.ToString();
if (token == null)
token = string.Empty;
return token;
}