I'm working in an application which receives a request from a Unity 3d project using WWWForm:
public IEnumerator UpdateServerStats()
{
this.gameSessionStats.SessionUpdateTime = System.DateTime.Now;
while (true)
{
WWWForm frm = new WWWForm();
frm.AddField("GameSessionStatsId", System.Convert.ToString(this.gameSessionStats.GameSessionStatsId));
frm.AddField("Platform", System.Convert.ToString(this.gameSessionStats.Platform));
frm.AddField("GameKey", System.Convert.ToString( this.gameSessionStats.GameKey));
frm.AddField("SessionId", System.Convert.ToString(this.gameSessionStats.SessionId));
frm.AddField("SessionStartDateTime", System.Convert.ToString(this.gameSessionStats.SessionStartDateTime));
frm.AddField("SessionUpdateTime", System.Convert.ToString(this.gameSessionStats.SessionUpdateTime));
frm.AddField("UserName", System.Convert.ToString(this.gameSessionStats.UserName));
string strPostUrl = string.Format("{0}/api/GameStats", RestFulServer);
WWW clientWeb = new WWW(strPostUrl, frm.data);
yield return clientWeb;
if (clientWeb.error != null && clientWeb.error.Length > 0)
Debug.Log(clientWeb.error);
else
Debug.Log(clientWeb.text);
yield return new WaitForSeconds(5);
}
}
Then I have a Web Api 2 Action
public HttpResponseMessage Post([FromBody]GameSessionStatsModel value)
{
PTIPortal.DA.Models.GameSessionStats newSessionStats = new DA.Models.GameSessionStats();
newSessionStats.GameSessionStatsId = value.GameSessionStatsId;
newSessionStats.Platform = value.Platform;
newSessionStats.GameKey = value.GameKey;
newSessionStats.SessionId = value.SessionId;
newSessionStats.SessionStartDateTime = value.SessionStartDateTime;
newSessionStats.SessionUpdateTime = value.SessionUpdateTime;
newSessionStats.UserName = value.UserName;
PTIPortal.DA.GameStatisticsDA gameStatsDA = new DA.GameStatisticsDA();
string result = gameStatsDA.CreateOrUpdateStatistics(newSessionStats);
HttpResponseMessage response = Request.CreateResponse(HttpStatusCode.OK, result);
return response;
}
Everything works ok, until I enable Open Id Authentication in the project, even if I set [AllowAnonymous] to the actions. This is the Startup.Auth.cs configuration, if I enable the line app.UseOpenIdConnectAuthentication, parameters are null, if I comment it parameters are received just fine.
app.UseOpenIdConnectAuthentication(
new OpenIdConnectAuthenticationOptions
{
ClientId = clientId,
Authority = Authority,
PostLogoutRedirectUri = postLogoutRedirectUri,
Notifications = new OpenIdConnectAuthenticationNotifications()
{
AuthenticationFailed = (context) =>
{
return Task.FromResult(0);
},
//
// If there is a code in the OpenID Connect response, redeem it for an access token and refresh token, and store those away.
//
AuthorizationCodeReceived = (context) =>
{
var code = context.Code;
ClientCredential credential = new ClientCredential(clientId, appKey);
string userObjectID = context.AuthenticationTicket.Identity.FindFirst(
"http://schemas.microsoft.com/identity/claims/objectidentifier").Value;
AuthenticationContext authContext = new AuthenticationContext(Authority, new NaiveSessionCache(userObjectID));
AuthenticationResult result = authContext.AcquireTokenByAuthorizationCode(
code, new Uri(HttpContext.Current.Request.Url.GetLeftPart(UriPartial.Path)), credential, graphResourceId);
AuthenticationHelper.token = result.AccessToken;
return Task.FromResult(0);
},
MessageReceived = (context) =>
{
return Task.FromResult(0);
},
RedirectToIdentityProvider = (context) =>
{
return Task.FromResult(0);
},
SecurityTokenReceived = (context) =>
{
return Task.FromResult(0);
},
SecurityTokenValidated = (context) =>
{
return Task.FromResult(0);
}
}
});
Am I missing something when building the request with the WWWForm, or in the server side in terms of configuration?
Thanks.