public async Task AddParameters_AddsCodeToResponse_WhenCodeIsEmitted()
        {
            // Arrange
            var provider = new DefaultAuthorizationResponseParameterProvider(new TimeStampManager());
            var response = new AuthorizationResponse()
            {
                Message      = new OpenIdConnectMessage(),
                RedirectUri  = "http://www.example.com/callback",
                ResponseMode = "query"
            };

            var context = new TokenGeneratingContext(
                new ClaimsPrincipal(),
                new ClaimsPrincipal(),
                new OpenIdConnectMessage()
            {
                State = "state"
            },
                new RequestGrants());

            context.InitializeForToken(TokenTypes.AuthorizationCode);
            context.AddToken(new TokenResult(new TestToken(TokenTypes.AuthorizationCode), "serialized_authorization_code"));

            // Act
            await provider.AddParameters(context, response);

            // Assert
            Assert.Equal("state", response.Message.State);
            Assert.Equal("serialized_authorization_code", response.Message.Code);
        }
Exemple #2
0
        public async Task AddParameters_AddsRefreshTokenToResponse_WhenRefreshTokenIsEmitted()
        {
            // Arrange
            var provider = new DefaultTokenResponseParameterProvider(new TimeStampManager());
            var response = new OpenIdConnectMessage();

            var context = new TokenGeneratingContext(
                new ClaimsPrincipal(),
                new ClaimsPrincipal(),
                new OpenIdConnectMessage(),
                new RequestGrants());

            context.InitializeForToken(TokenTypes.RefreshToken);
            context.AddToken(new TokenResult(new TestToken(TokenTypes.RefreshToken), "serialized_refresh_token"));

            // Act
            await provider.AddParameters(context, response);

            // Assert
            Assert.Equal("serialized_refresh_token", response.RefreshToken);
            Assert.True(response.Parameters.ContainsKey("refresh_token_expires_in"));
            Assert.Equal("3600", response.Parameters["refresh_token_expires_in"]);
            Assert.Equal("Bearer", response.TokenType);
        }
        public async Task AddParameters_AddsAccessTokenToResponse_WhenAccessTokenIsEmitted()
        {
            // Arrange
            var provider = new DefaultAuthorizationResponseParameterProvider(new TimeStampManager());
            var response = new AuthorizationResponse()
            {
                Message      = new OpenIdConnectMessage(),
                RedirectUri  = "http://www.example.com/callback",
                ResponseMode = "query"
            };

            var context = new TokenGeneratingContext(
                new ClaimsPrincipal(),
                new ClaimsPrincipal(),
                new OpenIdConnectMessage()
            {
                State = "state"
            },
                new RequestGrants()
            {
                Scopes = { ApplicationScope.OpenId, new ApplicationScope("resourceId", "read") }
            });

            context.InitializeForToken(TokenTypes.AccessToken);
            context.AddToken(new TokenResult(new TestToken(TokenTypes.AccessToken), "serialized_access_token"));

            // Act
            await provider.AddParameters(context, response);

            // Assert
            Assert.Equal("state", response.Message.State);
            Assert.Equal("serialized_access_token", response.Message.AccessToken);
            Assert.Equal("3600", response.Message.ExpiresIn);
            Assert.Equal("openid read", response.Message.Scope);
            Assert.Equal("Bearer", response.Message.TokenType);
        }