public static OpenIddictScopeModel ToModel(this OpenIddictScope entity)
    {
        if (entity == null)
        {
            return(null);
        }

        var model = new OpenIddictScopeModel
        {
            Id           = entity.Id,
            Description  = entity.Description,
            Descriptions = entity.Descriptions,
            DisplayName  = entity.DisplayName,
            DisplayNames = entity.DisplayNames,
            Name         = entity.Name,
            Properties   = entity.Properties,
            Resources    = entity.Resources
        };


        foreach (var extraProperty in entity.ExtraProperties)
        {
            model.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(model);
    }
Example #2
0
        public async Task ValidateAuthorizationRequest_RequestIsValidatedWhenRegisteredScopeIsSpecified()
        {
            // Arrange
            var scope = new OpenIddictScope();

            var manager = CreateScopeManager(instance =>
            {
                instance.Setup(mock => mock.FindByNamesAsync(
                                   It.Is <ImmutableArray <string> >(scopes => scopes.Length == 1 && scopes[0] == "scope_registered_in_database"),
                                   It.IsAny <CancellationToken>()))
                .ReturnsAsync(ImmutableArray.Create(scope));

                instance.Setup(mock => mock.GetNameAsync(scope, It.IsAny <CancellationToken>()))
                .Returns(new ValueTask <string>("scope_registered_in_database"));
            });

            var server = CreateAuthorizationServer(builder =>
            {
                builder.Services.AddSingleton(CreateApplicationManager(instance =>
                {
                    var application = new OpenIddictApplication();

                    instance.Setup(mock => mock.FindByClientIdAsync("Fabrikam", It.IsAny <CancellationToken>()))
                    .ReturnsAsync(application);

                    instance.Setup(mock => mock.ValidateRedirectUriAsync(application, "http://www.fabrikam.com/path", It.IsAny <CancellationToken>()))
                    .ReturnsAsync(true);

                    instance.Setup(mock => mock.GetClientTypeAsync(application, It.IsAny <CancellationToken>()))
                    .Returns(new ValueTask <string>(OpenIddictConstants.ClientTypes.Public));
                }));

                builder.RegisterScopes("scope_registered_in_options");

                builder.Services.AddSingleton(manager);
            });

            var client = new OpenIdConnectClient(server.CreateClient());

            // Act
            var response = await client.PostAsync(AuthorizationEndpoint, new OpenIdConnectRequest
            {
                ClientId     = "Fabrikam",
                Nonce        = "n-0S6_WzA2Mj",
                RedirectUri  = "http://www.fabrikam.com/path",
                ResponseType = OpenIdConnectConstants.ResponseTypes.Token,
                Scope        = "scope_registered_in_database scope_registered_in_options"
            });

            // Assert
            Assert.Null(response.Error);
            Assert.Null(response.ErrorDescription);
            Assert.Null(response.ErrorUri);
            Assert.NotNull(response.AccessToken);
        }
    public static OpenIddictScope ToEntity(this OpenIddictScopeModel model, OpenIddictScope entity)
    {
        Check.NotNull(model, nameof(model));
        Check.NotNull(entity, nameof(entity));

        entity.Description  = model.Description;
        entity.Descriptions = model.Descriptions;
        entity.DisplayName  = model.DisplayName;
        entity.DisplayNames = model.DisplayNames;
        entity.Name         = model.Name;
        entity.Properties   = model.Properties;
        entity.Resources    = model.Resources;

        foreach (var extraProperty in model.ExtraProperties)
        {
            entity.ExtraProperties.Remove(extraProperty.Key);
            entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(entity);
    }
    public static OpenIddictScope ToEntity(this OpenIddictScopeModel model)
    {
        Check.NotNull(model, nameof(model));

        var entity = new OpenIddictScope(model.Id)
        {
            Description  = model.Description,
            Descriptions = model.Descriptions,
            DisplayName  = model.DisplayName,
            DisplayNames = model.DisplayNames,
            Name         = model.Name,
            Properties   = model.Properties,
            Resources    = model.Resources
        };

        foreach (var extraProperty in model.ExtraProperties)
        {
            entity.ExtraProperties.Add(extraProperty.Key, extraProperty.Value);
        }

        return(entity);
    }