首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >在Angular中启用散列位置时,Okta重定向Url不起作用

在Angular中启用散列位置时,Okta重定向Url不起作用
EN

Stack Overflow用户
提问于 2018-07-06 14:27:35
回答 1查看 518关注 0票数 3

在我的angular 6应用程序中,我配置了oktaConfig对象,如下所示,并且运行良好,没有任何问题

代码语言:javascript
运行
复制
//okataConfig.ts

export const oktaConfig = {
  url: 'https://dev-501039.oktapreview.com',
  clientId: 'xxxxxxxxxxxxxxxxxxxxxx',
  issuer: 'xxxxxxxxxxxxxxxxxxxxxxxxxx',
  redirectUri: 'http://localhost:4200/implicit/callback',
};

//routing.ts

{path: '',component: DefaultLayoutComponent, canActivate: [AuthGuard]},
{path: 'implicit/callback',component: CallbackComponent},

但是当我启用散列位置重定向不起作用时,

代码语言:javascript
运行
复制
// app.module.ts

providers: [
  {
    provide: LocationStrategy,
    useClass: HashLocationStrategy,
  },
  AuthGuard, OktaAuthService
],

如何在路由中进行配置?

EN

回答 1

Stack Overflow用户

发布于 2020-12-28 18:16:28

在您的身份验证请求中将response_mode更改为query,而不是fragment (这会在url中添加另一个#)。这将起作用,您将获得代码和状态作为查询参数,如下所示-

http://{your.domain}/#/app/?code=xyz&state=pqr

代码语言:javascript
运行
复制
createRequest(code_challengeBuffer, response) {
  const code_challenge =
 this._ssoUtilityService.bufferToBase64UrlEncoded(code_challengeBuffer);
  const state = this._ssoUtilityService.createRandomString();
  const nonce = this._ssoUtilityService.createRandomString();
  this.appendParam('client_id', response.clientId, true);
  this.appendParam('nonce', nonce, true);
  this.appendParam('state', state, true);
  this.appendParam('code_challenge', code_challenge, true);
  this.appendParam('code_challenge_method', 'S256', true);
  this.appendParam('scope', 'openid profile email offline_access', true);
  this.appendParam('response_type', 'code', true);
  this.appendParam('response_mode', 'query', true);
  this.appendParam('redirect_uri', response.redirectUrl);
  window.location.href = this.url;
}
    
    // Added this function as IE11 does not support URL api
appendParam(key: string, value: string, addSeparator?: boolean) {
  this.url += key + '=' + encodeURIComponent(value);
  if (addSeparator) { this.url += '&'; }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/51204222

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档