angular - 在 Angular 中启用哈希位置时,Okta 重定向 URL 不起作用
问题描述
在我的 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
],
我应该如何配置路由?
解决方案
将response_mode更改为在您的身份验证请求中查询而不是片段(在 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 += '&'; }
}
推荐阅读
- jsf - h:inputFile 空指针异常
- excel - 我想在工作簿中的选定工作表上运行相同的宏
- javascript - 高级卡支付 SDK 在提交表单时显示错误
- php - 获取包含 PHP 中多个条目的数组的每个第二个值
- reactjs - 如何在 React 和 Firebase 中使用 Stripe
- python-3.x - 如果元素在 list1 中,则将 list2 中的元素替换为随机值
- java - 变量在我打印出来之前不会更新?
- git - 通过 windows cmd/powershell 去工作,但只有 git bash
- django - 安装 DRF 3.12 Alpha
- simulation - 我应该在 Drop off 中写什么代码?任意逻辑