public ActionResult GetAccessToken(string code)
        {
            var query = new Dictionary<string, string>();
            query.Add("client_id", Constants.GITHUB_CLIENT_ID);
            query.Add("client_secret", Constants.GITHUB_CLIENT_SEC);
            query.Add("code", code);
            query.Add("state", Constants.GITHUB_OAUTH_STATE);

            // send request
            JObject resp = Utility.MakeJsonHttpRequest(Constants.GITHUB_AK_URL, query);
            string accessToken = (string)resp["access_token"];

            // call sts and return
            // build cliam
            var claim = new ClaimsPrincipal();
            var id = new ClaimsIdentity();
            id.AddClaim(new Claim(Constants.CLAIM_TYPE_GITHUB_AK, accessToken));
            claim.AddIdentity(id);

            // send claim
            var sigingCredentials = new X509SigningCredentials(Utility.GetCertificate(Constants.CERTIFICATE_NAME));

            var config = new SecurityTokenServiceConfiguration(Constants.ISSUER_NAME, sigingCredentials);
            var sts = new CustomSecurityTokenService(config);

            var requestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(Request.Url);
            var responesMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, claim, sts);

            var formData = responesMessage.WriteFormPost();
            return new ContentResult() { Content = formData, ContentType = "text/html" };
        }
 public TokenService(SecurityTokenServiceConfiguration configuration, IUserRepository userRepository, IClaimsRepository claimsRepository, IIdentityProviderRepository identityProviderRepository, IClaimsTransformationRulesRepository claimsTransformationRulesRepository)
     : base(configuration)
 {
     UserRepository = userRepository;
     ClaimsRepository = claimsRepository;
     IdentityProviderRepository = identityProviderRepository;
     ClaimsTransformationRulesRepository = claimsTransformationRulesRepository;
 }
        /// <summary>
        /// Initializes an instance of <see cref="WSTrustServiceContract"/>
        /// </summary>
        /// <param name="securityTokenServiceConfiguration">Configuration object that initializes this instance.</param>
        public WSTrustServiceContract(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
        {
            if (securityTokenServiceConfiguration == null)
            {
                throw System.ServiceModel.DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenServiceConfiguration");
            }

            _securityTokenServiceConfiguration = securityTokenServiceConfiguration;
        }
Beispiel #4
0
 private string ProcessSignIn(Uri url, ClaimsPrincipal user)
 {
     var requestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(url);
     var config = new SecurityTokenServiceConfiguration(ConfigurationManager.AppSettings["SecurityTokenServiceEndpointUrl"], SecurityHelper.CreateSignupCredentialsFromConfig());
     var encryptionCredentials = SecurityHelper.CreateEncryptingCredentialsFromConfig();
     var sts = new CustomSecurityTokenService<AppMember>(WebConfigurationManager.AppSettings["LoginProviderName"], config, encryptionCredentials, _userStore);
     var responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, user, sts);
     return responseMessage.WriteFormPost();
 }
 public static SecurityTokenService GetSecurityTokenService()
 {
     var config = new SecurityTokenServiceConfiguration(
         ConfigurationManager.AppSettings["stsName"],
         CertificateFactory.GetSigningCredentials())
                  {
                      DefaultTokenLifetime = new TimeSpan(1, 0, 0, 0)
                  };
     return new DeveloperSecurityTokenService(config);
 }
Beispiel #6
0
 private static string ProcessSignIn(Uri url, ClaimsPrincipal user)
 {
     var requestMessage = (SignInRequestMessage)WSFederationMessage.CreateFromUri(url);
       var signingCredentials = new X509SigningCredentials(CustomSecurityTokenService.GetCertificate(ConfigurationManager.AppSettings["SigningCertificateName"]));
       var config = new SecurityTokenServiceConfiguration(ConfigurationManager.AppSettings["IssuerName"], signingCredentials);
       config.SecurityTokenHandlers.Clear();
       config.SecurityTokenHandlers.AddOrReplace(new CustomUsernameTokenHandler());
       var sts = new CustomSecurityTokenService(config);
       var responseMessage = FederatedPassiveSecurityTokenServiceOperations.ProcessSignInRequest(requestMessage, user, sts);
       return responseMessage.WriteFormPost();
 }
 public STSService(SecurityTokenServiceConfiguration configuration)
     : base(configuration)
 {
     _signingCredentials = new X509SigningCredentials(
         CertificateUtility.GetCertificateByThumbprint(
         StoreLocation.LocalMachine,
         StoreName.My,
         WebConfigurationManager.AppSettings["SigningCertificateThumbprint"].ToString()));
     if (!string.IsNullOrWhiteSpace(WebConfigurationManager.AppSettings["EncryptingCertificateName"].ToString()))
     {
         _encryptingCredentials = new X509EncryptingCredentials(
             CertificateUtility.GetCertificateByThumbprint(
             StoreLocation.LocalMachine, StoreName.My,
             WebConfigurationManager.AppSettings["EncryptingCertificateName"].ToString()));
     }
 }
        public SecurityTokenServiceConfiguration Create(string samlTwoTokenType, string stsName,
           X509Certificate2 samlTokenSigningCertificate, IEnumerable<string> rpAudiences)
        {
            var stsConfiguration = new SecurityTokenServiceConfiguration
            {
                DefaultTokenLifetime = new TimeSpan(0, 0, 30, 0),
                MaximumTokenLifetime = new TimeSpan(0, 0, 30, 0),
                DefaultTokenType = samlTwoTokenType,
                TokenIssuerName = stsName,
                SigningCredentials = new X509SigningCredentials(samlTokenSigningCertificate)
            };

            foreach (var rpAudience in rpAudiences)
            {
                stsConfiguration.AudienceRestriction.AllowedAudienceUris.Add(new Uri(rpAudience));
            }
            stsConfiguration.AudienceRestriction.AudienceMode = AudienceUriMode.Always;
            stsConfiguration.SecurityTokenService = typeof(TokenService);

            return stsConfiguration;
        }
 public CustomTokenService(SecurityTokenServiceConfiguration config)
     : base(config)
 {
 }
 public MultiProtocolSecurityTokenService(SecurityTokenServiceConfiguration configuration)
     : this(configuration, DefaultConfigurationRepository.Instance)
 {
 }
 public SystemIdentityTokenService(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
     : base(securityTokenServiceConfiguration)
 {
     this.securityTokenServiceConfiguration = securityTokenServiceConfiguration;
 }
Beispiel #12
0
 public GigaSTSService(SecurityTokenServiceConfiguration cfg) 
     : base(cfg)
 {
 }
        /// <summary>
        /// Use this constructor to initialize scope provider and token issuer certificate.
        /// </summary>
        /// <param name="securityTokenServiceConfiguration">The SecurityTokenServiceConfiguration that will have the related settings for the STS.</param>
        protected SecurityTokenService(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
        {
            if (securityTokenServiceConfiguration == null)
            {
                throw DiagnosticUtility.ExceptionUtility.ThrowHelperArgumentNull("securityTokenServiceConfiguration");
            }

            _securityTokenServiceConfiguration = securityTokenServiceConfiguration;
        }
 public MultiProtocolSecurityTokenService(SecurityTokenServiceConfiguration configuration, IConfigurationRepository multiProtocolConfiguration)
     : base(configuration)
 {
     this.multiProtocolConfiguration = multiProtocolConfiguration;
 }
 public CustomSecurityTokenService(SecurityTokenServiceConfiguration configuration)
     : base(configuration)
 {
     _signingCreds = new X509SigningCredentials(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, SIGNING_CERTIFICATE_NAME));
     _encryptingCreds = new X509EncryptingCredentials(CertificateUtil.GetCertificate(StoreName.My, StoreLocation.LocalMachine, ENCRYPTING_CERTIFICATE_NAME));
 }
        private ActionResult SignIn(string replyToAddress)
        {
            var user = HttpContext.Current.User.Identity.IsAuthenticated ? PreviouslyAuthenticated(replyToAddress) : AuthenticateAndCreateCookie(replyToAddress);
            var config = new SecurityTokenServiceConfiguration("http://sts.local", new X509SigningCredentials(LoadCertificate()));

            FederatedPassiveSecurityTokenServiceOperations.ProcessRequest(HttpContext.Current.Request, (ClaimsPrincipal) user, new CustomTokenService(config), HttpContext.Current.Response);
            return new HttpStatusCodeResult(HttpStatusCode.OK);
        }
 /// <summary>
 /// Initializes an instance of <see cref="WSTrustServiceHost"/>
 /// </summary>
 /// <param name="securityTokenServiceConfiguration">SecurityTokenServiceConfiguration instance used to initialize this ServiceHost.</param>
 /// <param name="baseAddresses">BaseAddress collection for the service host</param>
 /// <remarks>
 /// A default WSTrustServiceContract is instantiated using the SecurityTokenServiceConfiguration instance.
 /// The SecurityTokenServiceConfiguration instance is used for one-time initialization of the ServiceHost and
 /// setting properties on the configuration instance after the host is initialization may not result in
 /// behavioral changes.
 /// </remarks>
 public WSTrustServiceHost(SecurityTokenServiceConfiguration securityTokenServiceConfiguration, params Uri[] baseAddresses)
     : this(new WSTrustServiceContract(securityTokenServiceConfiguration), baseAddresses)
 {
 }
 public DeveloperSecurityTokenService(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
     : base(securityTokenServiceConfiguration)
 {
 }
 public CustomSecurityTokenService(SecurityTokenServiceConfiguration securityTokenServiceConfiguration)
     : base(securityTokenServiceConfiguration)
 {
 }
 public TokenService(SecurityTokenServiceConfiguration configuration)
     : base(configuration)
 {
     Container.Current.SatisfyImportsOnce(this);
 }
 public EmbeddedTokenService(SecurityTokenServiceConfiguration config)
     : base(config)
 {
 }
        public Serie2SecurityTokenService(SecurityTokenServiceConfiguration serie2SecurityTokenServiceConfiguration) :
            base(serie2SecurityTokenServiceConfiguration)
        {

        }
 public TwitterSecurityTokenService(SecurityTokenServiceConfiguration configuration, IConfigurationProvider configurationProvider)
     : base(configuration)
 {
     _configurationProvider = configurationProvider;
 }
Beispiel #24
0
 public SimpleSecurityTokenService(SecurityTokenServiceConfiguration simpleSecurityTokenServiceConfiguration, ClaimsIdentity claims)
     : base(simpleSecurityTokenServiceConfiguration)
 {
     this.m_claims = claims;
 }
 public CustomSecurityTokenService(SecurityTokenServiceConfiguration securityTokenServiceConfiguration, EncryptingCredentials encryptingCredentials, IDragonUserStore<AppMember> userStore)
     : base(securityTokenServiceConfiguration)
 {
     _encryptingCredentials = encryptingCredentials;
     _userStore = userStore;
 }
 public VkSecurityTokenService(SecurityTokenServiceConfiguration configuration, IPortalFrontendSettings settings)
     : base(configuration)
 {
     _settings = settings;
 }
 public TokenService(SecurityTokenServiceConfiguration configuration, IUserRepository userRepository, IClaimsRepository claimsRepository)
     : base(configuration)
 {
     UserRepository = userRepository;
     ClaimsRepository = claimsRepository;
 }