mirror of https://github.com/abpframework/abp.git
4 changed files with 24 additions and 23 deletions
@ -1,33 +1,32 @@ |
|||||
import { Inject, Injectable } from '@angular/core'; |
import { Inject, Injectable, Optional } from '@angular/core'; |
||||
import { OAuthStorage } from 'angular-oauth2-oidc'; |
import { OAuthStorage } from 'angular-oauth2-oidc'; |
||||
|
import { REQUEST } from '@angular/core'; |
||||
|
|
||||
@Injectable({ |
@Injectable({ providedIn: null }) |
||||
providedIn: null, |
|
||||
}) |
|
||||
export class ServerTokenStorageService implements OAuthStorage { |
export class ServerTokenStorageService implements OAuthStorage { |
||||
private cookies: Map<string, string> = new Map(); |
private cookies = new Map<string, string>(); |
||||
constructor(@Inject('cookies') c: string | undefined) { |
|
||||
if (c) { |
constructor(@Optional() @Inject(REQUEST) private req: Request | null) { |
||||
const cookieItems = c.split(';'); |
const cookieHeader = this.req?.headers.get('cookie') ?? ''; |
||||
for (const item of cookieItems) { |
for (const part of cookieHeader.split(';')) { |
||||
const index = item.indexOf('='); |
const i = part.indexOf('='); |
||||
if (index > -1) { |
if (i > -1) { |
||||
const key = item.slice(0, index).trim(); |
const k = part.slice(0, i).trim(); |
||||
const value = item.slice(index + 1).trim(); |
const v = decodeURIComponent(part.slice(i + 1).trim()); |
||||
this.cookies.set(key, value); |
this.cookies.set(k, v); |
||||
} |
|
||||
} |
} |
||||
} |
} |
||||
} |
} |
||||
|
|
||||
getItem(key: string): string { |
getItem(key: string): string { |
||||
if (this.cookies) { |
const fromCookie = this.cookies.get(key); |
||||
return this.cookies.get(key); |
if (fromCookie) { |
||||
|
return fromCookie; |
||||
} |
} |
||||
|
|
||||
return ''; |
return ''; |
||||
} |
} |
||||
|
|
||||
removeItem(key: string): void {} |
setItem(_k: string, _v: string): void {} |
||||
|
removeItem(_k: string): void {} |
||||
setItem(key: string, data: string): void {} |
|
||||
} |
} |
||||
|
|||||
Loading…
Reference in new issue