Я реализовал аутентификацию безопасности OWIN OAuth в. net mvc веб-API, и он размещен в AWS Elasti c Среде Beanstalk с URL-адресом, похожим на http://my-app.ap-southeast-2.elasticbeanstalk.com/myApi.
Пока все хорошо. Проблема возникает, когда я перенаправляю свой настраиваемый SSL-сертифицированный домен HTTPS (https://admin.my-app.com/myApi) в этот домен Elasti c Beanstalk. Я использую cloudflare для настроек DNS
private async Task<ResponseModel<AccessTokenModel>> GetUserToken(string UserName, string Password)
{
ResponseModel<AccessTokenModel> mResult = new ResponseModel<AccessTokenModel>();
using (var client = new HttpClient())
{
List<KeyValuePair<string, string>> requestParams = new List<KeyValuePair<string, string>>
{
new KeyValuePair<string, string>("grant_type", "password"),
new KeyValuePair<string, string>("username", UserName),
new KeyValuePair<string, string>("password", Password),
};
var request = HttpContext.Current.Request;
var tokenServiceUrl = request.Url.GetLeftPart(UriPartial.Authority) + request.ApplicationPath + "/Token";
var requestParamsFormUrlEncoded = new FormUrlEncodedContent(requestParams);
var tokenServiceResponse = await client.PostAsync(tokenServiceUrl, requestParamsFormUrlEncoded);
var responseString = await tokenServiceResponse.Content.ReadAsStringAsync();
var responseCode = tokenServiceResponse.StatusCode;
if (tokenServiceResponse.StatusCode == HttpStatusCode.OK)
{
mResult.Result = Newtonsoft.Json.JsonConvert.DeserializeObject<AccessTokenModel>(responseString);
mResult.Status = ResponseStatus.Success;
mResult.Message = "";
}
else
{
mResult.Message = "request.ApplicationPath:" + request.ApplicationPath + "\nStatusCode:" + tokenServiceResponse.StatusCode + "\n username,password=" + UserName + "," + Password + "\n"
+ tokenServiceResponse.ToString();
}
}
return mResult;
}
Startup.cs
/// <summary>
/// Wires up the OAuth infrastructure
/// </summary>
/// <param name="app"></param>
public void ConfigureOAuth(IAppBuilder app)
{
var OAuthServerOptions = new OAuthAuthorizationServerOptions()
{
AllowInsecureHttp = true,
TokenEndpointPath = new PathString("/Token"),
AccessTokenExpireTimeSpan = TimeSpan.FromDays(365),
Provider = new SimpleAuthorizationServerProvider()
};
// Token Generation
app.UseOAuthAuthorizationServer(OAuthServerOptions);
app.UseOAuthBearerAuthentication(new OAuthBearerAuthenticationOptions());
}
Любая помощь будет оценена, спасибо.