コード例 #1
0
 public BotAuthenticator(ICredentialProvider credentialProvider,
                         string openIdConfigurationUrl,
                         bool disableEmulatorTokens,
                         EndorsementsValidator validator = null)
 {
     if (credentialProvider == null)
     {
         throw new ArgumentNullException(nameof(credentialProvider));
     }
     this.credentialProvider     = credentialProvider;
     this.openIdConfigurationUrl = openIdConfigurationUrl;
     this.disableEmulatorTokens  = disableEmulatorTokens;
     this.validator = validator ?? DefaultEndorsementsValidator;
 }
コード例 #2
0
        public JwtTokenExtractor(TokenValidationParameters tokenValidationParameters, string metadataUrl, string[] allowedSigningAlgorithms, EndorsementsValidator validator)
        {
            // Make our own copy so we can edit it
            _tokenValidationParameters = tokenValidationParameters.Clone();
            _tokenValidationParameters.RequireSignedTokens = true;
            _allowedSigningAlgorithms = allowedSigningAlgorithms;
            _validator = validator;

            _openIdMetadata = _openIdMetadataCache.GetOrAdd(metadataUrl, key =>
            {
                return(new ConfigurationManager <OpenIdConnectConfiguration>(metadataUrl, new OpenIdConnectConfigurationRetriever()));
            });

            _endorsementsData = _endorsementsCache.GetOrAdd(metadataUrl, key =>
            {
                var retriever = new EndorsementsRetriever();
                return(new ConfigurationManager <IDictionary <string, string[]> >(metadataUrl, retriever, retriever));
            });;
        }
コード例 #3
0
 public BotAuthenticator(ICredentialProvider credentialProvider, EndorsementsValidator validator = null)
     : this(credentialProvider, JwtConfig.ToBotFromChannelOpenIdMetadataUrl, false, validator)
 {
 }
コード例 #4
0
 /// <summary>
 /// Creates an instance of bot authenticator.
 /// </summary>
 /// <param name="microsoftAppId"> The Microsoft app Id.</param>
 /// <param name="microsoftAppPassword"> The Microsoft app password.</param>
 /// <param name="validator"> The endorsements validator.</param>
 /// <remarks> This constructor sets the <see cref="openIdConfigurationUrl"/> to
 /// <see cref="JwtConfig.ToBotFromChannelOpenIdMetadataUrl"/>  and doesn't disable
 /// the self issued tokens used by emulator.
 /// </remarks>
 public BotAuthenticator(string microsoftAppId, string microsoftAppPassword, EndorsementsValidator validator = null)
     : this(new StaticCredentialProvider(microsoftAppId, microsoftAppPassword), validator)
 {
 }
コード例 #5
0
        public void UnaffinitizedActivityShouldPass()
        {
            var isEndorsed = EndorsementsValidator.Validate(string.Empty, new HashSet <string>(new[] { "right", "wrong" }));

            isEndorsed.Should().BeTrue();
        }
コード例 #6
0
        public void EndorsedChannelIdShouldPassWithTwoEndorsements()
        {
            var isEndorsed = EndorsementsValidator.Validate("right", new HashSet <string>(new [] { "right", "wrong" }));

            isEndorsed.Should().BeTrue();
        }
コード例 #7
0
        public void MismatchedEndorsementsChannelIdShouldFail()
        {
            var isEndorsed = EndorsementsValidator.Validate("right", new HashSet <string>(new[] { "wrong" }));

            isEndorsed.Should().BeFalse();
        }
コード例 #8
0
        public void UnendorsedChannelIdShouldFail()
        {
            var isEndorsed = EndorsementsValidator.Validate("channelOne", new HashSet <string>());

            isEndorsed.Should().BeFalse();
        }
コード例 #9
0
        public void NullEndorsementsParameterShouldThrow()
        {
            Action action = () => EndorsementsValidator.Validate("foo", null);

            action.Should().Throw <ArgumentNullException>().And.ParamName.Should().Be("endorsements");
        }
コード例 #10
0
        public void NullChannelIdParameterShouldPass()
        {
            var isEndorsed = EndorsementsValidator.Validate(null, new HashSet <string>());

            isEndorsed.Should().BeTrue();
        }
コード例 #11
0
        public void EndorsedChannelIdShouldPassWithTwoEndorsements()
        {
            bool isEndorsed = EndorsementsValidator.Validate("right", new[] { "right", "wrong" });

            isEndorsed.Should().BeTrue();
        }
コード例 #12
0
        public void MismatchedEndorsementsChannelIdShouldFail()
        {
            bool isEndorsed = EndorsementsValidator.Validate("right", new[] { "wrong" });

            isEndorsed.Should().BeFalse();
        }
コード例 #13
0
        public void UnendorsedChannelIdShouldFail()
        {
            bool isEndorsed = EndorsementsValidator.Validate("channelOne", new string[] { });

            isEndorsed.Should().BeFalse();
        }
コード例 #14
0
        public void NullChannelIdParameterShouldPass()
        {
            bool isEndorsed = EndorsementsValidator.Validate(null, new string[] { });

            isEndorsed.Should().BeTrue();
        }