zoukankan      html  css  js  c++  java
  • IdentityServer4 (三) 前后端分离

    1. 在上面的项目中,开通CORS。

    2.新建一个Angular项目,并安装oidc 包:

    ng new ids4Client
    cd ids4Client
    npm i oidc-client

    3. 修改appComponent 来访问IDS4

    export class AppComponent {
      title = 'ids4Client';
      mgr: Oidc.UserManager;
    
      constructor() {
         const config = {
            authority: 'https://localhost:6001',
            client_id: 'm2m.client',
            redirect_uri: 'https://localhost:5001',
            response_type: 'client_credentials',
            scope: 'scope1',
            post_logout_redirect_uri: 'https://localhost:5003/index.html',
          };
        this.mgr = new Oidc.UserManager(config);
      }
    
      login(): void {
        this.mgr.signinRedirect();
      }
    
      logout(): void {
        this.mgr.getUser().then( user => {
          const url = 'https://localhost:6001/identity';
    
          const xhr = new XMLHttpRequest();
          xhr.open('GET', url);
          xhr.onload = () => {
              console.log(xhr.status, JSON.parse(xhr.responseText));
          };
          xhr.setRequestHeader('Authorization', 'Bearer ' + user?.access_token);
          xhr.send();
      });
      }
    
      api(): void {
    
      }
    }

     这里的

    client_id: 'm2m.client',
    redirect_uri: 'https://localhost:5003/callback.html', 

    response_type: 'code',
    scope: 'openid profile api1',
    这些值要和 数据库中对应。 不然会出现类似下面的错误:
     
     
    气功波(18037675651)
  • 相关阅读:
    JOI2017FinalC JOIOI 王国
    JOISC2017C 手持ち花火
    P4336 [SHOI2016]黑暗前的幻想乡
    SP104 HIGH
    P3160 [CQOI2012]局部极小值
    P4965 薇尔莉特的打字机
    【BZOJ4361】isn
    P3506 [POI2010]MOT-Monotonicity 2
    P3214 [HNOI2011]卡农
    P3704 [SDOI2017]数字表格
  • 原文地址:https://www.cnblogs.com/qgbo/p/14587374.html
Copyright © 2011-2022 走看看