【发布时间】:2017-12-19 03:49:16
【问题描述】:
我正在尝试将 Identity Server 配置为与 Ionic 2 一起使用。我对如何配置重定向 URL 有点困惑。当我在浏览器中进行测试时。
我正在更新和集成 OIDC Cordova 组件。 旧组件 git hub 在这里: https://github.com/markphillips100/oidc-cordova-demo
我创建了一个 typescript 提供程序并在我的 app.module.ts 中注册了它
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs/Rx';
import 'rxjs/add/operator/map';
import { Component } from '@angular/core';
import * as Oidc from "oidc-client";
import { Events } from 'ionic-angular';
import { environment } from "../rules/environments/environment";
export class UserInfo {
user: Oidc.User = null;
isAuthenticated: boolean = false;
}
@Injectable()
export class OidcClientProvider {
USERINFO_CHANGED_EVENT_NAME: string = ""
userManager: Oidc.UserManager;
settings: Oidc.UserManagerSettings;
userInfo: UserInfo = new UserInfo();
constructor(public events:Events) {
this.settings = {
//authority: "https://localhost:6666",
authority: environment.identityServerUrl,
client_id: environment.clientAuthorityId,
//This doesn't work
post_logout_redirect_uri: "http://localhost/oidc",
redirect_uri: "http://localhost/oidc",
response_type: "id_token token",
scope: "openid profile",
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
//popupNavigator: new Oidc.CordovaPopupNavigator(),
//iframeNavigator: new Oidc.CordovaIFrameNavigator(),
}
this.initialize();
}
userInfoChanged(callback: Function) {
this.events.subscribe(this.USERINFO_CHANGED_EVENT_NAME, callback);
}
signinPopup(args?): Promise<Oidc.User> {
return this.userManager.signinPopup(args);
}
signoutPopup(args?) {
return this.userManager.signoutPopup(args);
}
protected initialize() {
if (this.settings == null) {
throw Error('OidcClientProvider required UserMangerSettings for initialization')
}
this.userManager = new Oidc.UserManager(this.settings);
this.registerEvents();
}
protected notifyUserInfoChangedEvent() {
this.events.publish(this.USERINFO_CHANGED_EVENT_NAME);
}
protected clearUser() {
this.userInfo.user = null;
this.userInfo.isAuthenticated = false;
this.notifyUserInfoChangedEvent();
}
protected addUser(user: Oidc.User) {
this.userInfo.user = user;
this.userInfo.isAuthenticated = true;
this.notifyUserInfoChangedEvent();
}
protected registerEvents() {
this.userManager.events.addUserLoaded(u => {
this.addUser(u);
});
this.userManager.events.addUserUnloaded(() => {
this.clearUser();
});
this.userManager.events.addAccessTokenExpired(() => {
this.clearUser();
});
this.userManager.events.addSilentRenewError(() => {
this.clearUser();
});
}
}
我正在尝试了解如何配置重定向 URL,以便可以在浏览器中正常进行身份验证。通常你会配置一个重定向 url 在登录后获取令牌和声明。
this.settings = {
authority: environment.identityServerUrl,
client_id: environment.clientAuthorityId,
post_logout_redirect_uri: "http://localhost:8100/oidc",
redirect_uri: "http://localhost:8100/oidc",
response_type: "id_token token",
scope: "openid profile AstootApi",
automaticSilentRenew: true,
filterProtocolClaims: true,
loadUserInfo: true,
//popupNavigator: new Oidc.CordovaPopupNavigator(),
//iframeNavigator: new Oidc.CordovaIFrameNavigator(),
}
Ionic 2 不使用 url 进行路由,假设我有一个组件 AuthenticationPage 处理存储身份验证令牌。
如何配置重定向 url 使其导航到身份验证页面,以便我可以在浏览器中进行测试?
【问题讨论】:
-
你是用inappbrowser插件访问idp的吗?
-
OIDC 提供商会为您处理这个问题,尽管我还没有在本机上测试它,因为我已更改为目标 PWA。如果这些信息中的任何一个被证明是有用的,请记得点赞。如果您有任何其他问题,请给我发表评论,我会尽力帮助您
-
我已经完成了一个简单的实现,它不适用于本机,因为它没有连接到 inappbrowser。适用于网页但不是本机。在这个阶段,如果你想使用自定义 idp,离子似乎不太适合目的
-
@Aeseir 在我的问题中看到两行注释掉的代码,这两行代码应该设置 oidc 以使用 idp 的弹出导航器。但是,如果您使用 Angular 4,则可以使用更好的 OIDC 管理器。
-
顺便说一句,我将研究 ResourceOwner 流作为替代方案并实现我自己的前端。这是不推荐的方式,但可以启用安静的登录和注销。保持联系以获取更新(我会得到一个 github repo)
标签: javascript angular cordova typescript ionic2