Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up user data when autoUserInfo is false => from id_token #1014

Merged
merged 5 commits into from
Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

- Improve AutoLoginGuard
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1015)
- Add support custom params during token exchange
- [PR](https://github.com/damienbod/angular-auth-oidc-client/pull/1010)

### 2021-03-12 Version 11.6.3

Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
"bugs": {
"url": "https://github.com/damienbod/angular-auth-oidc-client/issues"
},
"version": "11.6.3",
"version": "11.6.4",
"scripts": {
"ng": "ng",
"build": "npm run build-lib",
Expand Down
2 changes: 1 addition & 1 deletion projects/angular-auth-oidc-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@
"authorization"
],
"license": "MIT",
"version": "11.6.3",
"version": "11.6.4",
"description": "Angular Lib for OpenID Connect & OAuth2",
"schematics": "./schematics/collection.json"
}
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { TestBed } from '@angular/core/testing';
import { AuthStateService } from '../authState/auth-state.service';
import { AuthStateServiceMock } from '../authState/auth-state.service-mock';
import { ConfigurationProvider } from '../config/config.provider';
import { ConfigurationProviderMock } from '../config/config.provider-mock';
import { UserService } from '../userData/user-service';
import { UserServiceMock } from '../userData/user-service-mock';
import { FlowsDataService } from './flows-data.service';
Expand All @@ -14,13 +12,11 @@ describe('ResetAuthDataService', () => {
let userService: UserService;
let flowsDataService: FlowsDataService;
let authStateService: AuthStateService;
let configurationProvider: ConfigurationProvider;

beforeEach(() => {
TestBed.configureTestingModule({
providers: [
ResetAuthDataService,
{ provide: ConfigurationProvider, useClass: ConfigurationProviderMock },
{ provide: AuthStateService, useClass: AuthStateServiceMock },
{ provide: FlowsDataService, useClass: FlowsDataServiceMock },
{ provide: UserService, useClass: UserServiceMock },
Expand All @@ -30,7 +26,6 @@ describe('ResetAuthDataService', () => {

beforeEach(() => {
service = TestBed.inject(ResetAuthDataService);
configurationProvider = TestBed.inject(ConfigurationProvider);
userService = TestBed.inject(UserService);
flowsDataService = TestBed.inject(FlowsDataService);
authStateService = TestBed.inject(AuthStateService);
Expand All @@ -42,25 +37,12 @@ describe('ResetAuthDataService', () => {

describe('resetAuthorizationData', () => {
it('calls resetUserDataInStore when autoUserInfo is true', () => {
spyOnProperty(configurationProvider, 'openIDConfiguration').and.returnValue({ autoUserinfo: true });
const resetUserDataInStoreSpy = spyOn(userService, 'resetUserDataInStore');

service.resetAuthorizationData();

expect(resetUserDataInStoreSpy).toHaveBeenCalled();
});

it('does not call resetUserDataInStore when autoUserInfo is false', () => {
spyOnProperty(configurationProvider, 'openIDConfiguration').and.returnValue({ autoUserinfo: false });
const resetUserDataInStoreSpy = spyOn(userService, 'resetUserDataInStore');

service.resetAuthorizationData();

expect(resetUserDataInStoreSpy).not.toHaveBeenCalled();
});

it('calls correct methods', () => {
spyOnProperty(configurationProvider, 'openIDConfiguration').and.returnValue({ autoUserinfo: false });
const resetStorageFlowDataSpy = spyOn(flowsDataService, 'resetStorageFlowData');
const setUnauthorizedAndFireEventSpy = spyOn(authStateService, 'setUnauthorizedAndFireEvent');

Expand Down
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
import { Injectable } from '@angular/core';
import { AuthStateService } from '../authState/auth-state.service';
import { ConfigurationProvider } from '../config/config.provider';
import { UserService } from '../userData/user-service';
import { FlowsDataService } from './flows-data.service';

@Injectable()
export class ResetAuthDataService {
constructor(
private readonly configurationProvider: ConfigurationProvider,
private readonly authStateService: AuthStateService,
private readonly flowsDataService: FlowsDataService,
private readonly userService: UserService
) {}

resetAuthorizationData(): void {
if (this.configurationProvider.openIDConfiguration.autoUserinfo) {
// Clear user data. Fixes #97.
this.userService.resetUserDataInStore();
}

this.userService.resetUserDataInStore();
this.flowsDataService.resetStorageFlowData();
this.authStateService.setUnauthorizedAndFireEvent();
}
Expand Down
2 changes: 1 addition & 1 deletion projects/schematics/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "schematics",
"version": "11.6.3",
"version": "11.6.4",
"description": "A schematic for the Angular Lib for OpenID Connect & OAuth2",
"scripts": {
"build": "tsc -p tsconfig.json",
Expand Down
2 changes: 1 addition & 1 deletion projects/schematics/src/ng-add/actions/add-dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { addPackageJsonDependency, NodeDependency, NodeDependencyType } from '@s
const dependenciesToAdd = [
{
name: 'angular-auth-oidc-client',
version: '11.6.3',
version: '11.6.4',
},
];

Expand Down