小编Mop*_*opa的帖子

将ngModel中的对象传递给自定义控件Angular2

我想创建包含其他自定义控件的自定义控件,并使用连接所有自定义控件的ngModel.喜欢 :

PersonSearchComponent:

  • DeveloperSearchControl
    • 名称 - 一些字符串输入
    • ProffesionSelect - 期望ProffesionModel的自定义控件
  • BuildingSearchControl
    • 这里有一些自定义控件
  • CountryCustomControl - 期望CountryModel的自定义控件

  • PersonListComponent: - 由某些服务导入有关PersonSearchComponent中项目的数据

  • SomeOtherSearchComponent
    • DeveloperSearchControl - 可重用

所以现在我有工作版本,但我认为我做了一些坏事(也许我应该使用FormBuilder):

PersonSearch模板:

    <div>
            <developer-search-control [(ngModel)]="searchModel.developerSearchModel"></developer-search-control>
            <building-search-control [(ngModel)]="searchModel.buildingSearchModel"></building-search-control>
            <country-select [(ngModel)]="searchModel.countryModel"><country-select>
    </div>
Run Code Online (Sandbox Code Playgroud)

ParentSearch组件

...
export class PersonSearch {
  @Output() searchDataEmitter= new EventEmitter();//Exports data to above component which contains this, and listComponent
searchModel : PersonSearchModel : new PersonSearchModel();

    performSearch()
    {
        //gets data from service with searchModel and searchDataEmitter transpors it to above component
    }
}
Run Code Online (Sandbox Code Playgroud)

型号:PersonSearchModel:

developerSearchModel : DeveloperSearchModel = …
Run Code Online (Sandbox Code Playgroud)

angular2-forms angular2-ngmodel angular

4
推荐指数
1
解决办法
4478
查看次数

如何从 IdentityServer4 调用受保护的 API?

我想通过调用由 IS 验证的单独 api 将电子邮件服务与身份服务器项目分开。

我的问题是从身份服务器调用 api。目前,我在 IdentityServer 中有额外的“假”客户端正在调用 api。

这是客户端凭据流程的标准选项。

  1. 获取代币
  2. 返回令牌
  3. 调用API
  4. 检查令牌
  5. 返回数据

标准客户端凭证流程 但我想省略客户端。所以IdentityServer是客户端。我在 IS 内部创建了一个“假”客户端,我认为这是错误的做法?

IdentityServer 内的 MessageService.cs

 // Authenticating the fake client
 var disco = await DiscoveryClient.GetAsync("http://localhost:5000");
 var tokenClient = new TokenClient(disco.TokenEndpoint, "MailApiClient", "secret");
 var tokenResponse = await tokenClient.RequestClientCredentialsAsync("EmailScope");
 // Setting the token
 client.SetBearerToken(tokenResponse.AccessToken);
 var content = new StringContent(JsonConvert.SerializeObject(someMailModel));
 // Posting to api
 var response = await client.PostAsync(_emailSettings.RequestUri, content).ConfigureAwait(false);
Run Code Online (Sandbox Code Playgroud)

IS 内部的客户端

假客户端通过 IS 进行身份验证,然后将带有令牌的消息发送到 mailapi。我希望 IS 本身就是客户端,而不是在 IS 内部创建假客户端。因此IdentityServer将在没有中间件客户端的情况下调用api。

将来其他一些客户端也将使用 MailApi。

identityserver4

1
推荐指数
1
解决办法
1815
查看次数