“没有在设置上配置权限”-Angular 7,OIDC客户端

时间:2019-03-22 13:05:23

标签: angular oidc

我不知道这是oidc还是Angular或两者都是。相同字符串值的不同表示形式导致无法识别权限:

如果我直接输入值,可以使用:

authority: 'http://my.url.com'
// no errors

无法从服务中获取价值:

authority: this.settingsService.settings.stsAuthority
// MetadataService.getMetadata: No authority or metadataUrl configured on settings.
// console.log(this.settingsService.settings.stsAuthority) => 'http://my.url.com'
// console.log(typeof(this.settingsService.settings.stsAuthority)) => string

从另一个文件中的另一个类获取值的工作:

authority: Constants.stsAuthority
---
export class Constants {
    stsAuthority = 'http://my.url.com';
}

// no errors
// console.log(Constants.stsAuthority) => 'http://my.url.com'
// console.log(typeof(Constants.stsAuthority)) => string

如果该文件正在使用服务值,则无法从另一个文件的另一个类获取值:

authority: Constants.stsAuthority
---
export class Constants {
    stsAuthority = this.settingsService.settings.stsAuthority;
}
    // MetadataService.getMetadata: No authority or metadataUrl configured on settings.

未在服务值上使用字符串替换,但不会完全失败:

authority: Constants.stsAuthority
---
export class Constants {
    stsAuthority = `${this.settingsService.settings.stsAuthority}`;
}
    // GET https://rootUrl/**undefined**/.well-known/openid-configuration 404

现在您正在思考,“服务一定存在问题!”但是,每次我记录服务的价值时,我都会得到正确的价值。这是传递url值的服务代码:

@Injectable({
    providedIn: 'root'
})

export class SettingsService {
    public settings: Settings;

    constructor() { 
        this.settings = new Settings();
    }

}

这是另一个APP_INITIALIZER服务,可从环境获取设置值:

settings.http.service.ts

@Injectable({
    providedIn: "root"
})
export class SettingsHttpService {

    constructor(private http: HttpClient, private settingsService: SettingsService) { }

    initializeApp(): Promise<any> {

        return new Promise(
            (resolve) => {
                this.http.get('assets/settings.json')
                    .toPromise()
                    .then(response => {
                        this.settingsService.settings = <Settings>response;
                        resolve();
                    })
            }
        );
    }
}

这是结果,这是settings.service返回的结果:

{
    "clientRoot": "http://my.url.com",
}

0 个答案:

没有答案