public bool TryIssueToken(EndpointReference appliesTo, ClaimsPrincipal principal, string tokenType, out SecurityToken token) { token = null; var rst = new RequestSecurityToken { RequestType = RequestTypes.Issue, AppliesTo = appliesTo, KeyType = KeyTypes.Bearer, TokenType = tokenType }; try { var rstr = _sts.Issue(principal, rst); token = rstr.RequestedSecurityToken.SecurityToken; return(true); } catch (Exception e) { Tracing.Error("Failed to issue token. An exception occurred. " + e); return(false); } }
public bool TryIssueToken(EndpointReference appliesTo, ClaimsPrincipal principal, string tokenType, out SecurityToken token) { token = null; var rst = new RequestSecurityToken { RequestType = RequestTypes.Issue, AppliesTo = appliesTo, KeyType = KeyTypes.Bearer, TokenType = tokenType }; try { var rstr = _sts.Issue(principal, rst); token = rstr.RequestedSecurityToken.SecurityToken; return(true); } catch { return(false); } }
/// <summary> /// Requests a token from the issuer and builds a response with that token. /// </summary> /// <param name="requestMessage"></param> /// <param name="principal"></param> /// <param name="sts"></param> /// <param name="withRefreshToken"></param> /// <returns></returns> public static AccessTokenResponse ProcessAccessTokenRequest(AccessTokenRequest requestMessage, IPrincipal principal, SecurityTokenService sts, Boolean withRefreshToken) { if (null == requestMessage) throw new ArgumentNullException("requestMessage"); if (null == principal) throw new ArgumentNullException("principal"); if (null == sts) throw new ArgumentNullException("sts"); // Call issuer to create token // TODO /*var context = new WSTrustSerializationContext( sts.SecurityTokenServiceConfiguration.SecurityTokenHandlerCollectionManager, sts.SecurityTokenServiceConfiguration.CreateAggregateTokenResolver(), sts.SecurityTokenServiceConfiguration.IssuerTokenResolver);*/ var response = sts.Issue( ClaimsPrincipal.CreateFromPrincipal(principal), new WrapSerializer().CreateRequest(requestMessage)); // Create response var token = response.RequestedSecurityToken.SecurityToken; return WriteToken(token, withRefreshToken); }
/// <summary> /// Requests a token from the issuer and builds a response with that token. /// </summary> /// <param name="requestMessage"></param> /// <param name="principal"></param> /// <param name="sts"></param> /// <param name="withRefreshToken"></param> /// <returns></returns> public static AccessTokenResponse ProcessAccessTokenRequest(AccessTokenRequest requestMessage, IPrincipal principal, SecurityTokenService sts, Boolean withRefreshToken) { if (null == requestMessage) throw new ArgumentNullException("requestMessage"); if (null == principal) throw new ArgumentNullException("principal"); if (null == sts) throw new ArgumentNullException("sts"); // Call issuer to create token var response = sts.Issue( ClaimsPrincipal.CreateFromPrincipal(principal), new WrapSerializer().CreateRequest(requestMessage)); // Create response var token = response.RequestedSecurityToken.SecurityToken; return WriteToken(token, withRefreshToken); }