From f4d1a04303991ac9b42cc6596b104697b8482770 Mon Sep 17 00:00:00 2001 From: Willem Dantuma Date: Sat, 16 May 2020 10:46:55 +0200 Subject: [PATCH] Add profile scope, expose start and stop methods events service --- .../common/src/fm/services/event.service.ts | 21 ++++++++++++++----- src/app/id4AuthconfigFactory.ts | 6 +++--- 2 files changed, 19 insertions(+), 8 deletions(-) diff --git a/projects/common/src/fm/services/event.service.ts b/projects/common/src/fm/services/event.service.ts index 72d07f7..d71e489 100644 --- a/projects/common/src/fm/services/event.service.ts +++ b/projects/common/src/fm/services/event.service.ts @@ -2,7 +2,7 @@ import { Injectable } from '@angular/core'; import { IEventMessage } from '../models/event.message'; import { Subject, timer } from 'rxjs'; import { OAuthService } from 'angular-oauth2-oidc'; -import { HubConnection, HubConnectionBuilder, LogLevel ,HttpTransportType} from '@microsoft/signalr'; +import { HubConnection, HubConnectionBuilder, LogLevel ,HttpTransportType,HubConnectionState} from '@microsoft/signalr'; import { AppConfig } from "../shared/app.config"; @@ -31,12 +31,17 @@ export class EventService { this._connection.onreconnected( event => { this.Authenticate(); }); - this._connection.start().then(() => { - this.Authenticate(); - }); + this.Start(); } - Authenticate() { + Start() { + if(this._connection&&!(this._connection.state === HubConnectionState.Connected || this._connection.state === HubConnectionState.Connecting)) + this._connection.start().then(() => { + this.Authenticate(); + }); + } + + private Authenticate() { var accessToken = this.oauthService.getAccessToken(); if (accessToken) { this._connection.send('authenticate', this.oauthService.getAccessToken()); @@ -48,4 +53,10 @@ export class EventService { }, 800); } } + + Stop() { + if(this._connection&&(this._connection.state === HubConnectionState.Connected || this._connection.state === HubConnectionState.Connecting)) { + this._connection.stop(); + } + } } diff --git a/src/app/id4AuthconfigFactory.ts b/src/app/id4AuthconfigFactory.ts index ae45bdf..3fc6177 100644 --- a/src/app/id4AuthconfigFactory.ts +++ b/src/app/id4AuthconfigFactory.ts @@ -1,8 +1,8 @@ import { IAuthconfigFactory, AppConfig } from '@farmmaps/common'; -import { AuthConfig } from 'angular-oauth2-oidc'; +import { AuthConfig } from 'angular-oauth2-oidc'; import { Injectable } from "@angular/core"; -@Injectable() +@Injectable() export class Id4AuthconfigFactory implements IAuthconfigFactory { constructor() { @@ -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 = "api offline_access"; + authConfig.scope = "profile api offline_access"; authConfig.disableAtHashCheck = true; authConfig.responseType = "code"; authConfig.requireHttps = appConfig.getConfig("requireHttps");