Hi - I am not getting authenticated properly using ComponentSpace.Saml2. Below is the code snippet I am using. Please let me know what am I missing here.
Please advise.
-----------------------------------------------------------------------------------
Startup.cs
-----------------------------------------------------------------------------------
public void ConfigureServices(IServiceCollection services)
{
services.AddAuthentication().AddSaml(AppConstants.Saml2Scheme, AppConstants.Saml2Scheme, options =>
{
options.SignInScheme = IdentityServerConstants.ExternalCookieAuthenticationScheme;
options.PartnerName = () => ConfigSettings.PartnerName;
options.ConfigurationID = () => AppConstants.Default;
});
services.Configure<SamlConfigurations>(config => GetSamlConfiguration(config));
services.AddSaml();
}
-----------------------------------------------------------------------------------------------------------------------------
Controller - Account
Action Method - ExternalLogin
-----------------------------------------------------------------------------------------------------------------------------
[HttpGet]
public async Task<IActionResult> ExternalLogin(string provider, string returnUrl)
{
var authR = _interaction.GetAuthorizationContextAsync(returnUrl).Result;
string clientId = authR?.ClientId ?? "Default";
await _samlProvider.SetConfigurationIDAsync(clientId);
await _samlProvider.InitiateSsoAsync(relayState: returnUrl);
return new EmptyResult();
}
-----------------------------------------------------------------------------------------------------------------------------
SAML config file
-----------------------------------------------------------------------------------------------------------------------------
[
{
"ID": "Default",
"LocalServiceProviderConfiguration": {
"AssertionConsumerServiceUrl": "
http://localhost:44339/Saml/AssertionConsumerService_1", "Name": "
https://xxxxxxxxxxxxxxxxxxxxxxxxx", "LocalCertificates": [
{
"FileName": "*************",
"Password": "*************"
}
]
},
"PartnerIdentityProviderConfigurations": [
{
"Name": "
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "SignAuthnRequest": true,
"SignLogoutRequest": true,
"SignLogoutResponse": true,
"WantSamlResponseSigned": false,
"WantAssertionSigned": false,
"SingleLogoutServiceBinding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
"SingleSignOnServiceBinding": "urn:oasis:names:tc:SAML:2.0:bindings:HTTP-POST",
"SingleSignOnServiceUrl": "
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "SingleLogoutServiceUrl": "
https://xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "PartnerCertificates": [
{
"FileName": "*****************"
}
],
"NameIDFormat": "urn:oasis:names:tc:SAML:2.0:nameid-format:persistent"
}
]
}
]
------------------------------------------------------------------------------------------------------------------------------
Controller: Saml
Action Method: AssertionConsumerService_1
------------------------------------------------------------------------------------------------------------------------------
public async Task<ActionResult> AssertionConsumerService_1()
{
var ssoResult = await _samlServiceProvider.ReceiveSsoAsync();
var returnUrl = ssoResult.RelayState;
var info = await HttpContext.AuthenticateAsync(IdentityServerConstants.ExternalCookieAuthenticationScheme);
bool result = info.Succeeded;
//We are expecting it to be true so that we can write further logic.
}
------------------------------------------------------------