Browse Source

initial commit (for saving)

pull/18768/head
Sinan Öztürk 3 years ago
parent
commit
6bcfd844ca
  1. 6
      npm/ng-packs/packages/oauth/src/lib/strategies/auth-code-flow-strategy.ts
  2. 9
      npm/ng-packs/packages/oauth/src/lib/strategies/auth-password-flow-strategy.ts
  3. 29
      npm/ng-packs/packages/oauth/src/lib/utils/cookie-utils.ts

6
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))

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

29
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();
}
}
}
Loading…
Cancel
Save