在Angular中启用哈希位置时,Okta重定向网址不起作用

时间:2018-07-06 06:27:35

标签: angular okta

在我的angular 6应用程序中,我如下配置了oktaConfig对象,并且工作正常,没有任何问题

//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},

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

// app.module.ts

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

我应该如何配置路由?

1 个答案:

答案 0 :(得分:0)

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

<块引用>

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

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 += '&'; }
}