Private Sub Login_Click
redirecturi = "https://mywebsite.co.uk/finished"
' you need to replace the variables with the once from your boxcast account.
WebView1.LoadHtml($"https://auth.boxcast.com/oauth2/auth?response_type=code&client_id={client_id}&redirect_uri=${redirecturi}&scope=owner&state={state}"$)
End Sub
Private Sub WebView1_PageFinished (Url As String)
' Check if the process is finished the url will be https://mywebsite.co.uk/finished?code={code}&state={state}
' for this to work this page needs to exist . It could be a page with the message "logging you in..."
If (Url.tolowecase.contains("https://mywebsite.co.uk/finished") = 0) Then
' you need to extract the "code" and the "state" from the url string
'And check all Is good
' You also need to handle any errors or a cancelled login
'use the code to get the token
gettoken(code,redirecturi)
Log("Finished login " & Url)
End If
End Sub
private Sub gettoken( code As String, redirect As String)
Private s As String = $"${Your Client ID}:${your client secret}"$
Private su As stringutils
' note the different grant type and parameters
Private data As String = $"grant_type=authorization_code&code=${code}&code=${code}&redirect_url=${redirect}"$
job.Initialize("",Me)
job.PostString(https://auth.boxcast.com/oauth2/token",data)
job.GetRequest.SetHeader("Authorization","Basic "&su.EncodeBase64(s))
job.GetRequest.SetContentType("application/x-www-form-urlencoded")
Wait For (job) JobDone(job As HttpJob)
If (job.success) Then
Log(job.getstring)
End If
End Sub