I am getting localhost(portnumber)://signin-google?state=blahblahblah... once google signing in process completed.
Below is the main entry point from where API runs.
static void Main(string[] args)
{
using (var app = WebApp.Start<Startup>("http://localhost:8090"))
{
Process.Start("http://localhost:8090/api");
Console.WriteLine("Close this window to stop this server");
Console.ReadLine();
}
}
Below is my startup.cs class code
public void Configuration(IAppBuilder app)
{
var cookieOpts = new CookieAuthenticationOptions
{
LoginPath = new PathString("/account/login"),
CookieSecure = CookieSecureOption.SameAsRequest
};
app.UseCookieAuthentication(cookieOpts);
app.SetDefaultSignInAsAuthenticationType(cookieOpts.AuthenticationType);
var googleOpts = new GoogleOAuth2AuthenticationOptions
{
ClientId = "XXXXXXXXX",
ClientSecret = "XXXXXXXXX"
};
app.UseGoogleAuthentication(googleOpts);
var config = new HttpConfiguration();
config.Services.Replace(typeof(IHttpControllerTypeResolver), new ControllerResolver());
config.MapHttpAttributeRoutes();
app.UseWebApi(config);
}
The controller from where google sign in challage page is executed is
[RoutePrefix("account"), AllowAnonymous]
public class AccountController : ApiController
{
[HttpGet, Route("login")]
public IHttpActionResult Login(string returnUrl)
{
var authProps = new AuthenticationProperties
{
RedirectUri = returnUrl
};
Request.GetOwinContext().Authentication.Challenge(authProps, "Google");
return StatusCode(HttpStatusCode.Unauthorized);
}
[HttpGet, Route("logoff")]
public IHttpActionResult Logout()
{
Request.GetOwinContext().Authentication.SignOut();
return Ok();
}
}
The controller for which I am using google authorisation is
[RoutePrefix("api"), Authorize]
public class DefaultController : ApiController
{
[HttpGet, Route("")]
public IHttpActionResult Get()
{
return Ok("Hello, world!");
}
}
Everything works fine 1. When application starts it checks for google login 2. If not then it will redirect to google sign in page 3. after sign in into google it is redirecting back to localhost(portnumber)://signin-google?state=blahblahblah..
I guess it should redirect to actual api - in my case it should have http://localhost:portnumer:/api
Below is the trace capture file for quick reference - Trace-log-is-here
Thank you in advance..:)
Source Code - https://github.com/BDChaudhari90/OAuthGoogleSelfHost