コード例 #1
0
        public async Task ShouldStoreMultipleCredentials()
        {
            // given
            await TokenProvider.GetAccessTokenForRequestAsync();

            var otherProvider = new CamundaCloudTokenProviderBuilder()
                                .UseAuthServer(_requestUri)
                                .UseClientId(_clientId         = "OTHERID")
                                .UseClientSecret(_clientSecret = "OTHERSECRET")
                                .UseAudience(_audience         = "OTHER_AUDIENCE")
                                .Build();

            otherProvider.SetHttpMessageHandler(MessageHandlerStub);
            otherProvider.TokenStoragePath = TokenStoragePath;
            Token = "OTHER_TOKEN";

            // when
            var token = await otherProvider.GetAccessTokenForRequestAsync();

            // then
            Assert.AreEqual("OTHER_TOKEN", token);
            var files = Directory.GetFiles(TokenStoragePath);

            Assert.AreEqual(1, files.Length);
            var tokenFile   = files[0];
            var content     = File.ReadAllText(tokenFile);
            var credentials = JsonConvert.DeserializeObject <Dictionary <string, CamundaCloudTokenProvider.AccessToken> >(content);

            Assert.AreEqual(credentials.Count, 2);
            Assert.AreEqual(token, credentials["OTHER_AUDIENCE"].Token);
            Assert.AreEqual("REQUESTED_TOKEN", credentials["AUDIENCE"].Token);
        }
        public void Init()
        {
            TokenProvider = new CamundaCloudTokenProviderBuilder()
                            .UseAuthServer("https://local.de")
                            .UseClientId("ID")
                            .UseClientSecret("SECRET")
                            .UseAudience("AUDIENCE")
                            .Build();

            MessageHandlerStub = new HttpMessageHandlerStub();
            TokenProvider.SetHttpMessageHandler(MessageHandlerStub);
            TokenStoragePath = Path.GetTempPath() + ".zeebe/";
            TokenProvider.TokenStoragePath = TokenStoragePath;
            ExpiresIn = 3600;
            Token     = "REQUESTED_TOKEN";
        }
コード例 #3
0
        public void Init()
        {
            _requestUri   = "https://local.de";
            _clientId     = "ID";
            _clientSecret = "SECRET";
            _audience     = "AUDIENCE";
            TokenProvider = new CamundaCloudTokenProviderBuilder()
                            .UseAuthServer(_requestUri)
                            .UseClientId(_clientId)
                            .UseClientSecret(_clientSecret)
                            .UseAudience(_audience)
                            .Build();

            MessageHandlerStub = new HttpMessageHandlerStub();
            TokenProvider.SetHttpMessageHandler(MessageHandlerStub);
            TokenStoragePath = Path.GetTempPath() + ".zeebe/";
            TokenProvider.TokenStoragePath = TokenStoragePath;
            ExpiresIn = 3600;
            Token     = "REQUESTED_TOKEN";
        }
コード例 #4
0
        public async Task ShouldNotUseCachedFileForOtherAudience()
        {
            // given
            Token = "STORED_TOKEN";
            await TokenProvider.GetAccessTokenForRequestAsync();

            var otherProvider = new CamundaCloudTokenProviderBuilder()
                                .UseAuthServer(_requestUri)
                                .UseClientId(_clientId         = "OTHERID")
                                .UseClientSecret(_clientSecret = "OTHERSECRET")
                                .UseAudience(_audience         = "OTHER_AUDIENCE")
                                .Build();

            otherProvider.SetHttpMessageHandler(MessageHandlerStub);
            otherProvider.TokenStoragePath = TokenStoragePath;
            Token = "OTHER_TOKEN";

            // when
            var token = await otherProvider.GetAccessTokenForRequestAsync();

            // then
            Assert.AreEqual("OTHER_TOKEN", token);
        }