diff --git a/projects/common/src/fm/actions/app-common.actions.ts b/projects/common/src/fm/actions/app-common.actions.ts index 2bd72fc..963ef5c 100644 --- a/projects/common/src/fm/actions/app-common.actions.ts +++ b/projects/common/src/fm/actions/app-common.actions.ts @@ -4,6 +4,7 @@ import { IItemTypes } from '../models/item.types'; import { IListItem } from '../models/list.item'; import { IUser } from '../models/user'; import { IItem } from '../models/item'; +import { UserInfo } from 'angular-oauth2-oidc'; export const INITUSER = '[AppCommon] InitUser'; export const INITUSERSUCCESS = '[AppCommon] InitUserSuccess'; @@ -62,7 +63,7 @@ export class InitUser implements Action { export class InitUserSuccess implements Action { readonly type = INITUSERSUCCESS; - constructor(public user:IUser ) { } + constructor(public user:IUser,public userinfo:UserInfo ) { } } export class InitUserPackagesSuccess implements Action { diff --git a/projects/common/src/fm/effects/app-common.effects.ts b/projects/common/src/fm/effects/app-common.effects.ts index 63e2bd2..fdeb82f 100644 --- a/projects/common/src/fm/effects/app-common.effects.ts +++ b/projects/common/src/fm/effects/app-common.effects.ts @@ -1,9 +1,9 @@ import { Injectable } from '@angular/core'; import { Router } from '@angular/router'; -import { OAuthService } from 'angular-oauth2-oidc'; +import { OAuthService,UserInfo } from 'angular-oauth2-oidc'; import { Store, Action } from '@ngrx/store'; import { Effect, Actions,ofType } from '@ngrx/effects'; -import { Observable , defer , of } from 'rxjs'; +import { Observable , defer , of,from } from 'rxjs'; import { withLatestFrom,mergeMap,switchMap,map,catchError} from 'rxjs/operators'; import * as appCommonActions from '../actions/app-common.actions'; import * as appCommonReducers from '../reducers/app-common.reducer'; @@ -44,9 +44,10 @@ export class AppCommonEffects { ofType(appCommonActions.INITUSER), withLatestFrom(this.store$.select(appCommonReducers.selectGetInitialized)), switchMap(([action, initialized]) => { - if(!initialized) { + if(!initialized) { return this.userService$.getCurrentUser().pipe( - map((user: IUser) => new appCommonActions.InitUserSuccess(user)), + withLatestFrom(from(this.oauthService$.loadUserProfile())), + switchMap(([user,userInfo]) => {return of(new appCommonActions.InitUserSuccess(user,userInfo as UserInfo))} ), catchError(error => of(new appCommonActions.Fail(error)))) } else { return []; diff --git a/projects/common/src/fm/reducers/app-common.reducer.ts b/projects/common/src/fm/reducers/app-common.reducer.ts index ec74a38..ec47ac0 100644 --- a/projects/common/src/fm/reducers/app-common.reducer.ts +++ b/projects/common/src/fm/reducers/app-common.reducer.ts @@ -36,7 +36,12 @@ export function reducer(state = initialState, action: appCommonActions.Actions ) switch (action.type) { case appCommonActions.INITUSERSUCCESS: { let a = action as appCommonActions.InitUserSuccess; - return tassign(state, { user: a.user,initialized: true }); + var user:IUser = { + code:a.user.code, + email:a.userinfo["email"], + name:a.userinfo["name"] + }; + return tassign(state, { user: user,initialized: true }); } case appCommonActions.INITROOTSUCCESS: { let a = action as appCommonActions.InitRootSuccess; diff --git a/src/app/id4AuthconfigFactory.ts b/src/app/id4AuthconfigFactory.ts index 3fc6177..64f54a1 100644 --- a/src/app/id4AuthconfigFactory.ts +++ b/src/app/id4AuthconfigFactory.ts @@ -14,7 +14,7 @@ export class Id4AuthconfigFactory implements IAuthconfigFactory { authConfig.redirectUri = window.location.origin + "/cb"; authConfig.clientId = appConfig.getConfig("clientId"); authConfig.customQueryParams = { audience: appConfig.getConfig("audience") }; - authConfig.scope = "profile api offline_access"; + authConfig.scope = "openid profile api offline_access"; authConfig.disableAtHashCheck = true; authConfig.responseType = "code"; authConfig.requireHttps = appConfig.getConfig("requireHttps");