Angularjs IdentityServer 4-invaid_客户端错误

Angularjs IdentityServer 4-invaid_客户端错误,angularjs,oauth-2.0,identityserver4,Angularjs,Oauth 2.0,Identityserver4,我是Identity Server的新手。我以前没有配置过。但我在做一个项目需要它。 该API将为Angular JS客户端、iOS应用程序和Android应用程序提供服务。我们需要实施认证、授权和客户授权 注意:我试图在同一Web API项目中配置Identity Server和我的API 我按照文档进行了操作,并按照以下方式配置了Identity Server: 在startup.cs中的ConfigureServices() 我已经按照文档进行了操作,并按照以下方式配置了客户机信息

我是Identity Server的新手。我以前没有配置过。但我在做一个项目需要它。 该API将为Angular JS客户端、iOS应用程序和Android应用程序提供服务。我们需要实施认证、授权和客户授权

注意:我试图在同一Web API项目中配置Identity Server和我的API

我按照文档进行了操作,并按照以下方式配置了Identity Server:

在startup.cs中的
ConfigureServices()

我已经按照文档进行了操作,并按照以下方式配置了客户机信息

        public static IEnumerable<Client> GetClients () {
        return new Client[] {
                    new Client {
                    ClientId = "javascritpClient",
                    ClientName = "JavaScript Client",
                    AllowedGrantTypes = { "wechat_grant" },
                    AllowAccessTokensViaBrowser = true,
                    AllowedCorsOrigins = { "http://localhost:5202" },
                    AllowedScopes = { "api1" },
                    ClientSecrets = { new Secret ("secret".Sha256 ()) }
                    }
        };
    }
公共静态IEnumerable GetClient(){
返回新客户端[]{
新客户{
ClientId=“JavaScriptClient”,
ClientName=“JavaScript客户端”,
AllowedGrantTypes={“微信授权”},
AllowAccessTokensViaBrowser=true,
AllowedCorsOrigins={”http://localhost:5202" },
AllowedScopes={“api1”},
ClientSecrets={newsecret(“Secret.Sha256())}
}
};
}
现在,因为我想使用JS、iOS和Android,我只想从IdentityServer获取访问令牌,然后使用访问令牌进行身份验证和授权

为此,我尝试从JS客户端访问/connect/token

但是我得到一个无效的客户端错误

@Injectable()
export class OauthService {
  private http: Http;
  public constructor(http: Http) {
    this.http = http;
  }

  public async getDiscoveryInfos(issuer: string): Promise<DiscoveryInfos> {
    if (!issuer.endsWith('/')) {
      issuer += '/';
    }
    issuer += '.well-known/openid-configuration';
    return this.http.get(issuer).map(response => {
      return response.json();
    }).toPromise();
  }

  public async getToken(): Promise<any> {
    const headers = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
    const discovery = await this.getDiscoveryInfos('http://localhost:5200');
    return this.http.post(discovery.token_endpoint, {
      grant_type: 'wechat_grant',
      userCode: 'userCodeAA',
      client_id: 'javascritpClient',
      client_secret: 'secret',
      scope:'api1'
    }, { headers: headers }).map(response => response.json()).toPromise();
  }

}
@Injectable()
导出类OauthService{
私有http:http;
公共构造函数(http:http){
this.http=http;
}
公共异步getDiscoveryInfos(颁发者:字符串):承诺{
如果(!issuer.endsWith('/')){
发行人+='/';
}
发卡机构+='。众所周知的/openid配置';
返回此.http.get(issuer.map)(响应=>{
返回response.json();
}).toPromise();
}
公共异步getToken():承诺

服务器响应“错误”:“无效的\u客户端”

我在服务器端遇到的错误是
“找不到客户端标识符”

1-为什么我会出现这个错误


2-由于我需要在JS中以编程方式获取令牌,我需要使用/connect/Token,我在这方面正确吗?我在正确的路径上吗?

在ng2中,使用如下方法:

public Token(data: SigninModel): Observable<any> {
    this.options = new RequestOptions({ headers: this.headers });
    this.headers.append('Content-Type', 'application/x-www-form-urlencoded');
    const url = this.urlBase + `connect/token`;
    const param = new URLSearchParams();
    param.set('grant_type', 'password');
    param.set('client_Id', 'javascritpClient');
    param.set('client_secret', 'secret');
    param.set('scope', 'offline_access');
    param.set('username', data.username);
    param.set('password', data.password);
    return this.http.post(url, `${param.toString()}`, this.options)
        .map((response: Response) => {
            return (response.json()); 
        })
        .catch(this.handleError);
}
公共令牌(数据:SigninModel):可观察{
this.options=newrequestoptions({headers:this.headers});
this.headers.append('Content-Type','application/x-www-form-urlencoded');
const url=this.urlBase+`connect/token`;
const param=新的URLSearchParams();
参数集('grant_type','password');
参数集('client_Id','javaScriptClient');
参数集('client_secret','secret');
参数集('scope','offline_access');
参数集('username',data.username);
参数集('password',data.password);
返回this.http.post(url,`${param.toString()}`,this.options)
.map((响应:响应)=>{
返回(response.json());
})
.接住(这个.把手错误);
}
@Injectable()
export class OauthService {
  private http: Http;
  public constructor(http: Http) {
    this.http = http;
  }

  public async getDiscoveryInfos(issuer: string): Promise<DiscoveryInfos> {
    if (!issuer.endsWith('/')) {
      issuer += '/';
    }
    issuer += '.well-known/openid-configuration';
    return this.http.get(issuer).map(response => {
      return response.json();
    }).toPromise();
  }

  public async getToken(): Promise<any> {
    const headers = new Headers({ "Content-Type": "application/x-www-form-urlencoded" });
    const discovery = await this.getDiscoveryInfos('http://localhost:5200');
    return this.http.post(discovery.token_endpoint, {
      grant_type: 'wechat_grant',
      userCode: 'userCodeAA',
      client_id: 'javascritpClient',
      client_secret: 'secret',
      scope:'api1'
    }, { headers: headers }).map(response => response.json()).toPromise();
  }

}
public Token(data: SigninModel): Observable<any> {
    this.options = new RequestOptions({ headers: this.headers });
    this.headers.append('Content-Type', 'application/x-www-form-urlencoded');
    const url = this.urlBase + `connect/token`;
    const param = new URLSearchParams();
    param.set('grant_type', 'password');
    param.set('client_Id', 'javascritpClient');
    param.set('client_secret', 'secret');
    param.set('scope', 'offline_access');
    param.set('username', data.username);
    param.set('password', data.password);
    return this.http.post(url, `${param.toString()}`, this.options)
        .map((response: Response) => {
            return (response.json()); 
        })
        .catch(this.handleError);
}