- Created a .net core AWS Serverless Application.
- Cognito is used to authenticate.
- Users and App clients have been configured.
- When I ran the solution locally it worked fine (bearing in mind it was http).
When I published using the publish wizard and hit the new url with
postman (https://myendpoint/Prod) I immediately get:{ "message": "Forbidden" }
I can only guess that it is to do with http / https here.
Controller for Authentication:
public class AuthenticationController : Controller
{
[HttpPost]
[Route("api/signin")]
public async Task<ActionResult<string>> SignIn(User user)
{
var cognito = new AmazonCognitoIdentityProviderClient(RegionEndpoint.APSoutheast2);
var request = new AdminInitiateAuthRequest
{
UserPoolId = "ap-southeast-2_MYPOOLID",
ClientId = "MYCLIENTID",
AuthFlow = AuthFlowType.ADMIN_USER_PASSWORD_AUTH
};
request.AuthParameters.Add("USERNAME", user.Username);
request.AuthParameters.Add("PASSWORD", user.Password);
var response = await cognito.AdminInitiateAuthAsync(request);
return Ok(response.AuthenticationResult);
}
}
Startup.ConfigureServices
services.AddSingleton<IAuthorizationHandler, CognitoGroupAuthorisationHandler>();
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
options.TokenValidationParameters = new TokenValidationParameters
{
ValidIssuer = "https://cognito-idp.ap-southeast-2.amazonaws.com/ap-southeast-2_MYPOOL",
ValidateIssuerSigningKey = true,
ValidateIssuer = true,
ValidateLifetime = true,
ValidAudience = "MYKEY",
ValidateAudience = true
};
});
EDIT #1 It appears I resolved the forbidden msg but am now getting a 500 error.
Postman yields: 500 Internal Server Error
Testing with API Gateway (Api Gateway->Resources-> /{proxy+}->Any->Test->Post)
Method: POST Proxy is set to : /api/signin Request Body:
{
"username": "xxx",
"password":"yyy"
}
yields:
{"Strict-Transport-Security":"max-age=2592000","ErrorType":"AmazonCognitoIdentityProviderException","X-Amzn-Trace-Id":"Root=xxxxx;Sampled=0","Content-Type":""}