Add profile scope, expose start and stop methods events service
FarmMaps.Develop/FarmMapsLib/pipeline/head This commit looks good Details

feature/MinimizeSolution
Willem Dantuma 2020-05-16 10:46:55 +02:00
parent 44cac3e1ab
commit f4d1a04303
2 changed files with 19 additions and 8 deletions

View File

@ -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();
}
}
}

View File

@ -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");