diff --git a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts index c9708d699e..c3443427d2 100644 --- a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts +++ b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts @@ -2,11 +2,17 @@ import { noop } from '@abp/ng.core'; import { Params } from '@angular/router'; import { from, of } from 'rxjs'; import { AuthFlowStrategy } from './auth-flow-strategy'; +import { deleteAllCookies } from '../utils/cookie-utils'; export class AuthCodeFlowStrategy extends AuthFlowStrategy { readonly isInternalAuth = false; + private rememberMeKey = 'remember_me' async init() { + console.log('code flow'); + const accessToken = this.oAuthService.getAccessToken(); + let parsedToken = JSON.parse(atob(accessToken.split(".")[1]));; + return super .init() .then(() => this.oAuthService.tryLogin().catch(noop)) diff --git a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-password-flow-strategy.ts b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-password-flow-strategy.ts index 1958865e23..74ffc3bd30 100644 --- a/npm/ng-packs/packages/oauth/src/lib/strategies/auth-password-flow-strategy.ts +++ b/npm/ng-packs/packages/oauth/src/lib/strategies/auth-password-flow-strategy.ts @@ -7,11 +7,7 @@ import { AuthFlowStrategy } from './auth-flow-strategy'; import { pipeToLogin, removeRememberMe } from '../utils/auth-utils'; import { LoginParams } from '@abp/ng.core'; import { clearOAuthStorage } from '../utils/clear-o-auth-storage'; - -function getCookieValueByName(name: string) { - const match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); - return match ? match[2] : ''; -} +import { getCookieValueByName } from '../utils/cookie-utils'; export class AuthPasswordFlowStrategy extends AuthFlowStrategy { readonly isInternalAuth = true; @@ -40,7 +36,8 @@ export class AuthPasswordFlowStrategy extends AuthFlowStrategy { } async init() { - if (!getCookieValueByName(this.cookieKey) && localStorage.getItem(this.storageKey)) { + if (!(getCookieValueByName(this.cookieKey) === 'true') && localStorage.getItem(this.storageKey)) { + removeRememberMe(this.localStorageService); this.oAuthService.logOut(); } diff --git a/npm/ng-packs/packages/oauth/src/lib/utils/cookie-utils.ts b/npm/ng-packs/packages/oauth/src/lib/utils/cookie-utils.ts new file mode 100644 index 0000000000..e31d4944ff --- /dev/null +++ b/npm/ng-packs/packages/oauth/src/lib/utils/cookie-utils.ts @@ -0,0 +1,29 @@ +export function getCookieValueByName(name: string) { + const cookiesArray = document.cookie.split(';'); + + for (let i = 0; i < cookiesArray.length; i++) { + let cookie = cookiesArray[i].trim(); + + if (cookie.startsWith(name + '=')) { + return cookie.substring(name.length + 1); + } + } + return null; +} + +export function deleteAllCookies() { + var cookies = document.cookie.split("; "); + for (var c = 0; c < cookies.length; c++) { + var d = window.location.hostname.split("."); + while (d.length > 0) { + var cookieBase = encodeURIComponent(cookies[c].split(";")[0].split("=")[0]) + '=; expires=Thu, 01-Jan-1970 00:00:01 GMT; domain=' + d.join('.') + ' ;path='; + var p = location.pathname.split('/'); + document.cookie = cookieBase + '/'; + while (p.length > 0) { + document.cookie = cookieBase + p.join('/'); + p.pop(); + }; + d.shift(); + } + } +} \ No newline at end of file