Try using this post as a guideline. But it is not really hard, just a POST request using the client ID and secret as basic authorization plus a x-url-encoded form data body with just one field.
The function below was written from memory and a few StackOverflow searches. On success the result should be the whole JSON string returned by the token endpoint. I don’t have Delphi anymore so I can’t test it, but it shouldn’t look much different than this:
function CreateAccessToken(const ClientID, ClientSecret: string): string;
var
HTTP: TIdHttp;
SSLHandler: TIdSSLIOHandlerSocketOpenSSL;
FormData: TIdMultipartFormDataStream;
Response: TStringStream;
begin
HTTP := TIdHttp.Create(nil);
FormData := TIdMultipartFormDataStream.Create;
Response := TStringStream.Create('');
SSLHandler := TIdSSLIOHandlerSocketOpenSSL.Create;
try
try
// SSL support
SSLHandler.SSLOptions.SSLVersions := [sslvTLSv1_1, sslvTLSv1_2];
HTTP.IOHandler := SSLHandler;
// Authorization header
HTTP.Request.BasicAuthentication := True;
HTTP.Request.UserName := ClientID;
HTTP.Request.Password := ClientSecret;
// Body payload
FormData.AddFormField('grant_type', 'client_credentials');
// Excecute the request
HTTP.Post('https://us.battle.net/oauth/token', FormData, Response);
Result := Response.DataString;
except
on E:Exception do
// Handle exceptions or
raise;
end
finally
Response.Free;
FormData.Free;
SSLHandler.Free;
HTTP.Free;
end
end;