示例#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);
        }
示例#2
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);
        }