登录界面:

实现Component:login-form.component.html:

上图第1行,触发submitForm函数:

用了promise技术:

  /*** Authorize with ResourceOwnerPasswordFlow.** @param userId* @param password** @return token response from the lib*/authorizeWithPasswordFlow(userId: string,password: string): Promise<TokenResponse> {return this.oAuthService.fetchTokenUsingPasswordFlow(userId, password);}

使用user和password换取token:

 /*** Uses password flow to exchange userName and password for an access_token.* @param userName* @param password* @param headers Optional additional http-headers.*/fetchTokenUsingPasswordFlow(userName, password, headers = new HttpHeaders()) {this.assertUrlNotNullAndCorrectProtocol(this.tokenEndpoint, 'tokenEndpoint');return new Promise((resolve, reject) => {/*** A `HttpParameterCodec` that uses `encodeURIComponent` and `decodeURIComponent` to* serialize and parse URL parameter keys and values.** @stable*/let params = new HttpParams({ encoder: new WebHttpUrlEncodingCodec() }).set('grant_type', 'password').set('scope', this.scope).set('username', userName).set('password', password);if (this.useHttpBasicAuth) {const header = btoa(`${this.clientId}:${this.dummyClientSecret}`);headers = headers.set('Authorization', 'Basic ' + header);}if (!this.useHttpBasicAuth) {params = params.set('client_id', this.clientId);}if (!this.useHttpBasicAuth && this.dummyClientSecret) {params = params.set('client_secret', this.dummyClientSecret);}if (this.customQueryParams) {for (const key of Object.getOwnPropertyNames(this.customQueryParams)) {params = params.set(key, this.customQueryParams[key]);}}headers = headers.set('Content-Type', 'application/x-www-form-urlencoded');this.http.post(this.tokenEndpoint, params, { headers }).subscribe(tokenResponse => {this.debug('tokenResponse', tokenResponse);this.storeAccessTokenResponse(tokenResponse.access_token, tokenResponse.refresh_token, tokenResponse.expires_in ||this.fallbackAccessTokenExpirationTimeInSec, tokenResponse.scope, this.extractRecognizedCustomParameters(tokenResponse));this.eventsSubject.next(new OAuthSuccessEvent('token_received'));resolve(tokenResponse);}, err => {this.logger.error('Error performing password flow', err);this.eventsSubject.next(new OAuthErrorEvent('token_error', err));reject(err);});});}

更多Jerry的原创文章,尽在:“汪子熙”:

SAP Spartacus用户登录的实现相关推荐

  1. SAP Spartacus 用户登录成功后,Access Token 持久化到浏览器 local storage 的执行原理

    下图第1487行代码,调用Angular HTTP library,往this.tokenEndpoint指向的API发送HTTP post请求,参数为用户在login form里输入的用户名和密码: ...

  2. SAP Spartacus用户登录之后读取用户信息的HTTP请求

    让我有点吃惊的是,如下图所示: 明明我是以中文登录,但这个HTTP请求的url里,lang参数仍然是en: https://spartacus-dev0.eastus.cloudapp.azure.c ...

  3. SAP Spartacus 用户请求中的 current id 是从哪里来的

    从 SAP Spartacus 成功登录之后,能在 Local Storage 里观察到 userId 为 current: 这个 current id 从哪里来的呢?在 Spartacus 应用初始 ...

  4. SAP Spartacus 用户认证的实现

    文章目录 UserAuthModule Authentication Flow AuthService Storing Tokens and User Identifiers 用户认证的典型流程和包含 ...

  5. SAP Spartacus的登录页面的用户名显示逻辑

    SAP Spartacus登录页面如下图所示: 通过login form用户输入的用户名和密码去换取token,拿到token后,调用另一个API,将token作为Authorization字段输入: ...

  6. SAP Spartacus的登录验证机制 - user login Authentication

    用户输入用户名和密码,点击login之后,向如下http endpoint发起POST请求: url: https://spartacus-dev2.eastus.cloudapp.azure.com ...

  7. SAP Spartacus如何判断用户是否已经成功登录

    该逻辑实现在文件auth.service.ts内: isUserLoggedIn(): Observable<boolean> {return this.authStorageServic ...

  8. SAP Spartacus 找不到登录入口的问题 - 如何使用 Schematics 安装 user package

    如下图所示:本地打开 SAP Spartacus 页面,右上角找不到登录链接: 查看 package.json,发现因为我没有安装 @spartacus/user 这个 package: @spart ...

  9. 如何自行找出 SAP Spartacus 查询用户信息的 API Service 类

    成功登录 SAP Spartacus 之后,在 Chrome 开发者工具 Network tab 里能看到一条读取用户信息的网络请求: https://20.83.184.244:9002/occ/v ...

最新文章

  1. 辞旧迎新,总结2010,展望2011
  2. docker 无法正常启动或版本信息会报错 Cannot connect to the Docker daemon at
  3. Altium Designer-Net has no driving source解决办法
  4. Yii CDBCriteria常用方法
  5. android shell用户界面,shell界面下安装和卸载Android应用程序(apk包)
  6. 什么是初效过滤器_初效过滤器怎么样 初效过滤器特点介绍【详解】
  7. Erlang 位串和二进制数据
  8. 梅耶·马斯克对话邓文迪 直播首秀将上线今日头条、抖音
  9. MySQL Replication主从复制环境下修改主库IP
  10. normalize.css下载
  11. 医院职工离职申请证明模板,共计10篇
  12. subli快速度创建html,Shortcut to comment out a block of code with subli
  13. 百度深度学习工程师认证(已通过)
  14. 程序员职业发展路径图:从菜鸟工程师到高级架构师(转)
  15. 指数型基金今年来收益排行榜
  16. halcon与C#混合编程(三)数字识别
  17. 程序员计算机常用快捷键,19个程序员都爱不释手的键盘快捷键,快来看看你知道几个又用过几个吧!...
  18. 软件智能:aaas系统中的数学程序与技术服务之1 序篇之 绪言
  19. 排查Spring 无法启动的问题
  20. Simulink电机控制代码生成-----关于PI控制器参数整定的一点总结

热门文章

  1. 【Altium Designer】DatabaseLib的使用方法
  2. Android安全机制(2) Android Permission权限控制机制
  3. [开源 .NET 跨平台 Crawler 数据采集 爬虫框架: DotnetSpider] [一] 初衷与架构设计
  4. 在Webstorm中配置Compass Watcher
  5. C# asp:Repeater DataSource ListT
  6. android 中ImageView的scaletype属性
  7. Five bugs in five minutes...
  8. springboot scheduled多线程
  9. Objective-C ,ios,iphone开发基础:picker控件详解与使用,(实现省市的二级联动)
  10. shell的变量以及常见符号