I came across few resources in internet where google authentication is done through web api.
So , I wanted to try the same in asp.net mvc web app in similar way.I am stuck in the middle on how to fetch the redirectUri for my application.
1.App is registered in google, clientid and secret is mentioned in Authconfig.cs.
2.Upon click of my button i have to redirect to GoogleSignIn page.The redirectUrl(authrequestUrl) which will take the user to signin page is something i am not getting.
In Web api,requesting below url(GET request) will return the redirectUrl as response.
http://localhost:xxxx/api/Account/ExternalLogin?returnUrl=%2f&generateState=true
which i can use for redirecting the user to google sign in page upon click of my sign in button from my Login View.
MyLogin.cshtml
<body>
<row>
<button id="GoogleBtn" type="button" class="col-md-5 btn">Google</button>
</row>
</body>
<script type="text/javascript">
$document.ready(function ()
{
$('#GoogleBtn').click(function ()
{
window.location.href="RedirectUrl"
});
});
</script>
In Asp.net MVc, there exists two actions - external login and externallogincallback
Calling external login- http://localhost:49837/Account/ExternalLogin?provider=Google&returnUrl=%2f will return Error -'The required anti-forgery form field "__RequestVerificationToken" is not present.'
Calling externallogincallback- http://localhost:49837/Account/ExternalLoginCallback?provider=Google&returnUrl=%2f&generateState=true will redirect to another View (~/Views/Account/Login), where it contains a button for Google. Upon clicking that button it takes me to Google SignInPage with all request parameters to process and sign in.
I want my app to redirect directly to Google SignIn page without going to account/login view and then being redirected to SignIn page upon clicking Google Button.
Someone help me in how to fetch the redirectUrl for my mvc application.
Update:
The Oauth request url/Google sign in request url is what i had been looking for,I got confused with the redirectUrl. I found a way to build the request Url and i successfully made the call using javascript.