public Token Refresh(ServerDto serverDto, LoginDto loginDto, Token tokenToRefresh) { IAuthenticationService tokenService = null; if (serverDto.TokenType == TokenType.SAML) tokenService = new SamlTokenService(_webRequestManager); else tokenService = new JwtTokenService(_webRequestManager); return tokenService.Refresh(serverDto, loginDto, tokenToRefresh); }
public AuthTokenDto Login(ServerDto serverDto, LoginDto loginDto, string clientId) { IAuthenticationService tokenService = null; if(serverDto.TokenType == TokenType.SAML) tokenService = new SamlTokenService(_webRequestManager); else tokenService = new JwtTokenService(_webRequestManager); return tokenService.Authenticate(serverDto, loginDto, clientId); }
public ContentResult Get() { var wsFederationMessage = ValidateRequestType(); ValidateWsFederationMessage(wsFederationMessage); var samlTokenService = new SamlTokenService( new RealmTracker(HttpContext), new SecurityTokenServiceConfigurationFactory()); var signInResponseMessage = samlTokenService.CreateResponseContainingToken(HttpContext.Request.Url); return new ContentResult { Content = signInResponseMessage.WriteFormPost() }; }
public Token Refresh(ServerDto serverDto, LoginDto loginDto, Token tokenToRefresh) { IAuthenticationService tokenService = null; if (serverDto.TokenType == TokenType.SAML) { tokenService = new SamlTokenService(_webRequestManager); } else { tokenService = new JwtTokenService(_webRequestManager); } return(tokenService.Refresh(serverDto, loginDto, tokenToRefresh)); }
public AuthTokenDto Login(ServerDto serverDto, LoginDto loginDto, string clientId) { IAuthenticationService tokenService = null; if (serverDto.TokenType == TokenType.SAML) { tokenService = new SamlTokenService(_webRequestManager); } else { tokenService = new JwtTokenService(_webRequestManager); } return(tokenService.Authenticate(serverDto, loginDto, clientId)); }
public ContentResult Token() { var wsFederationMessage = ValidateRequestType(); ValidateWsFederationMessage(wsFederationMessage); var samlTokenService = new SamlTokenService( new RealmTracker(HttpContext), new SecurityTokenServiceConfigurationFactory()); var signInResponseMessage = samlTokenService.CreateResponseContainingToken(HttpContext.Request.Url); return(new ContentResult { Content = signInResponseMessage.WriteFormPost() }); }
public ActionResult IssueResponse() { if (Request.Form.HasKeys()) { if (Request.Form["SAMLResponse"] != null) { var samlResponse = Request.Form["SAMLResponse"]; var responseDecoded = Encoding.UTF8.GetString(Convert.FromBase64String(HttpUtility.HtmlDecode(samlResponse))); Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityToken token; using (var sr = new StringReader(responseDecoded)) { using (var reader = XmlReader.Create(sr)) { reader.ReadToFollowing("Assertion", "urn:oasis:names:tc:SAML:2.0:assertion"); var coll = Microsoft.IdentityModel.Tokens.SecurityTokenHandlerCollection.CreateDefaultSecurityTokenHandlerCollection(); token = (Microsoft.IdentityModel.Tokens.Saml2.Saml2SecurityToken)coll.ReadToken(reader.ReadSubtree()); } } var realm = token.Assertion.Conditions.AudienceRestrictions[0].Audiences[0].ToString(); var issuer = token.Assertion.Issuer.Value; var rstr = new RequestSecurityTokenResponse { TokenType = Constants.TokenKeys.TokenType, RequestType = Constants.TokenKeys.RequestType, KeyType = Constants.TokenKeys.KeyType, Lifetime = new Lifetime(token.Assertion.IssueInstant, token.Assertion.Conditions.NotOnOrAfter), AppliesTo = new System.ServiceModel.EndpointAddress(new Uri(realm)), RequestedSecurityToken = new RequestedSecurityToken(GetElement(responseDecoded)) }; var principal = GetClaimsIdentity(rstr); if (principal != null) { var claimsPrinciple = ClaimsPrincipal.CreateFromPrincipal(principal); var requestMessage = new SignInRequestMessage(new Uri("http://foo"), realm); var ipc = new SamlTokenServiceConfiguration(issuer); SecurityTokenService identityProvider = new SamlTokenService(ipc); var responseMessage = Microsoft.IdentityModel.Web.FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, claimsPrinciple, identityProvider); Microsoft.IdentityModel.Web.FederatedPassiveSecurityTokenServiceOperations.ProcessSignInResponse(responseMessage, System.Web.HttpContext.Current.Response); } } } return(View("Error")); }