The process of obtaining Access and Refresh Tokens
The process of obtaining access and refresh tokens begins with user authentication. Developers initiate one of the HyperID authentication flows by redirecting the user to the HyperID authentication URI with the response_type parameter set to code.
Upon successful user authentication and consent, HyperID responds by returning code. The code can be exchanged for access and refresh tokens through the API call. This step is required to secure the authentication process and should be performed by your application's backend for enhanced security.
To illustrate the process, let's take a look at the following examples of HTTP requests and responses:
As we mentioned earlier, the code is obtained from the authentication step, while the redirect_uri, client_id and client_secret are retrieved from your client's configuration settings (see the Client Registration chapter for details).
It's important to note that HyperID only accepts the redirect_uri specified in the client configuration and the one is used in the previous authentication step, otherwise no tokens will be issued.
var client = new HttpClient();
var request = new HttpRequestMessage(HttpMethod.Post, "https://login.hypersecureid.com/auth/realms/HyperID/protocol/openid-connect/token");
var collection = new List<KeyValuePair<string, string>>();
collection.Add(new("grant_type", "authorization_code"));
collection.Add(new("code", "your_authorization_code"));
collection.Add(new("redirect_uri", "https%3A%2F%2Fyourapp.com%2Fcb"));
collection.Add(new("client_id", "your_app_client_id"));
collection.Add(new("client_secret", "your_app_client_secret"));
var content = new FormUrlEncodedContent(collection);
request.Content = content;
var response = await client.SendAsync(request);
response.EnsureSuccessStatusCode();
Console.WriteLine(await response.Content.ReadAsStringAsync());