OAuth2 client credentials implementations

VB NET

    '//Add RestSharp to your nuget package manager
    '//imports RestSharp at the top
    '//Set api key
    Dim api_key As String = "{your api key here}"
    Dim api_secret As String = "{your api secret here}"
    Dim region As String = "EU"
    '//encode the creds
    Dim encoded As String = System.Convert.ToBase64String(System.Text.Encoding.GetEncoding("ISO-8859-1").GetBytes(api_key + ":" + api_secret))
    Dim Rclient As New RestClient("https://" & region & ".battle.net/oauth/token")
    Rclient.Timeout = -1
    Dim rRequest As New RestRequest(Method.POST)
    rRequest.AddParameter("grant_type", "client_credentials")
    rRequest.AddHeader("Authorization", "Basic " & encoded)
    rRequest.AddHeader("Content-Type", "application/x-www-form-urlencoded")
    Dim rResponse As IRestResponse = Rclient.Execute(rRequest)
    '//write out the access token
    MsgBox(rResponse.Content)

Hope this helps someone who needs it. Can be converted to C# Easily for any .NET people out there.

Obviously the links are butchered as I cannot post links here, so just remove the spacing. :slight_smile:

1 Like