I need to access this main site https://www.truecaller.com/search/eg/xxxx via Powershell.
I wrote many PowerShell scripts to Invoke-WebRequest using forms authentication, but this time the website is using external authentication from Google or Microsoft.
From a google search, I noted that I have to get the access authorization code first.
The problem that the site configured from google API as a web application, not a desktop application, so it refused to give me the authorization code on the web page.
I do not own the website, so I can not do any change from the web site or the authentication side.
Normally when I open the main site at my browser and select to authenticate from Google it redirects me to
https://accounts.google.com/o/oauth2/v2/auth/identifier?response_type=code&client_id=22378802832-klpcj5dosalhnu0vshg3hjm9qgidmp8j.apps.googleusercontent.com&redirect_uri=https%3A%2F%2Fwww.truecaller.com%2Fauth%2Fgoogle%2Fcallback&scope=https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.email%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fuserinfo.profile%20https%3A%2F%2Fwww.googleapis.com%2Fauth%2Fcontacts.readonly&flowName=GeneralOAuthFlow
Then after authentication, it redirects me back to the main site
I'm using the below code to capture the authorization code to be used later at another comannd to get the access token then invoke-webrequest to the main site.
$clientId = "22378802832-klpcj5dosalhnu0vshg3hjm9qgidmp8j.apps.googleusercontent.com"
$redirect_uri1 = "https%3A%2F%2Fwww.truecaller.com%2Fauth%2Fgoogle%2Fcallback"
$redirect_uri2 = "urn:ietf:wg:oauth:2.0:oob"
$scopes = "https://www.googleapis.com/auth/userinfo.email%20https://www.googleapis.com/auth/userinfo.profile%20https://www.googleapis.com/auth/contacts.readonly"
Start-Process "https://accounts.google.com/o/oauth2/v2/auth?client_id=$clientId&scope=$scopes&access_type=offline&response_type=code&redirect_uri=$redirect_uri1"
When i use $redirect_uri1
After google ask me on the web to allow the application access to my account, it Goes to the web site normal and not give me the authorization code because the redirect URL is https://www.truecaller.com/auth/google/callback
When i use $redirect_uri2
Google refused to complete the authentication process because I use the URL Redirection desktop URL, and this clientID is configured to use web redirection and I face the below error.
My question, how I can use Invoke-WebRequest or Invoke-RestMethod to this main web site that using external authentication via OAuth, is it something double?