mirror of https://github.com/abpframework/abp
commit
e911d9fddc
@ -0,0 +1,56 @@
|
||||
using System;
|
||||
using IdentityModel.Client;
|
||||
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
|
||||
using Microsoft.Extensions.DependencyInjection;
|
||||
using Microsoft.Extensions.Options;
|
||||
|
||||
namespace Microsoft.AspNetCore.Authentication.Cookies;
|
||||
|
||||
public static class CookieAuthenticationOptionsExtensions
|
||||
{
|
||||
/// <summary>
|
||||
/// Introspect access token on validating the principal.
|
||||
/// </summary>
|
||||
/// <param name="options"></param>
|
||||
/// <param name="oidcAuthenticationScheme"></param>
|
||||
/// <returns></returns>
|
||||
public static CookieAuthenticationOptions IntrospectAccessToken(this CookieAuthenticationOptions options, string oidcAuthenticationScheme = "oidc")
|
||||
{
|
||||
var originalHandler = options.Events.OnValidatePrincipal;
|
||||
options.Events.OnValidatePrincipal = async principalContext =>
|
||||
{
|
||||
originalHandler?.Invoke(principalContext);
|
||||
|
||||
if (principalContext.Principal != null && principalContext.Principal.Identity != null && principalContext.Principal.Identity.IsAuthenticated)
|
||||
{
|
||||
var accessToken = principalContext.Properties.GetTokenValue("access_token");
|
||||
if (!accessToken.IsNullOrWhiteSpace())
|
||||
{
|
||||
var openIdConnectOptions = principalContext.HttpContext.RequestServices.GetRequiredService<IOptionsMonitor<OpenIdConnectOptions>>().Get(oidcAuthenticationScheme);
|
||||
if (openIdConnectOptions.Configuration == null && openIdConnectOptions.ConfigurationManager != null)
|
||||
{
|
||||
openIdConnectOptions.Configuration = await openIdConnectOptions.ConfigurationManager.GetConfigurationAsync(principalContext.HttpContext.RequestAborted);
|
||||
}
|
||||
|
||||
var response = await openIdConnectOptions.Backchannel.IntrospectTokenAsync(new TokenIntrospectionRequest
|
||||
{
|
||||
Address = openIdConnectOptions.Configuration?.IntrospectionEndpoint ?? openIdConnectOptions.Authority.EnsureEndsWith('/') + "connect/introspect",
|
||||
ClientId = openIdConnectOptions.ClientId,
|
||||
ClientSecret = openIdConnectOptions.ClientSecret,
|
||||
Token = accessToken
|
||||
});
|
||||
|
||||
if (response.IsActive)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
principalContext.RejectPrincipal();
|
||||
await principalContext.HttpContext.SignOutAsync(principalContext.Scheme.Name);
|
||||
}
|
||||
};
|
||||
|
||||
return options;
|
||||
}
|
||||
}
|
@ -0,0 +1,23 @@
|
||||
using System.Threading.Tasks;
|
||||
using Volo.Abp.AspNetCore.Components.Web.Configuration;
|
||||
using Volo.Abp.DependencyInjection;
|
||||
|
||||
namespace Volo.Abp.AspNetCore.Components.WebAssembly.Configuration;
|
||||
|
||||
[Dependency(ReplaceServices = true)]
|
||||
public class BlazorWebAssemblyCurrentApplicationConfigurationCacheResetService :
|
||||
ICurrentApplicationConfigurationCacheResetService,
|
||||
ITransientDependency
|
||||
{
|
||||
private readonly WebAssemblyCachedApplicationConfigurationClient _webAssemblyCachedApplicationConfigurationClient;
|
||||
|
||||
public BlazorWebAssemblyCurrentApplicationConfigurationCacheResetService(WebAssemblyCachedApplicationConfigurationClient webAssemblyCachedApplicationConfigurationClient)
|
||||
{
|
||||
_webAssemblyCachedApplicationConfigurationClient = webAssemblyCachedApplicationConfigurationClient;
|
||||
}
|
||||
|
||||
public async Task ResetAsync()
|
||||
{
|
||||
await _webAssemblyCachedApplicationConfigurationClient.InitializeAsync();
|
||||
}
|
||||
}
|
@ -0,0 +1,28 @@
|
||||
import { Injectable } from '@angular/core';
|
||||
|
||||
@Injectable({
|
||||
providedIn: 'root',
|
||||
})
|
||||
export class AbpLocalStorageService implements Storage {
|
||||
constructor() {}
|
||||
[name: string]: any;
|
||||
get length(): number {
|
||||
return localStorage.length;
|
||||
}
|
||||
|
||||
clear(): void {
|
||||
localStorage.clear();
|
||||
}
|
||||
getItem(key: string): string {
|
||||
return localStorage.getItem(key);
|
||||
}
|
||||
key(index: number): string {
|
||||
return localStorage.key(index);
|
||||
}
|
||||
removeItem(key: string): void {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
setItem(key: string, value: string): void {
|
||||
localStorage.setItem(key, value);
|
||||
}
|
||||
}
|
@ -0,0 +1,52 @@
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
|
||||
import { AbpLocalStorageService } from '../services/local-storage.service';
|
||||
|
||||
describe('LocalStorageService', () => {
|
||||
let service: AbpLocalStorageService;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({});
|
||||
service = TestBed.inject(AbpLocalStorageService);
|
||||
});
|
||||
|
||||
it('should be created', () => {
|
||||
expect(service).toBeTruthy();
|
||||
});
|
||||
|
||||
it('should be called getItem', () => {
|
||||
const spy = jest.spyOn(service, 'getItem');
|
||||
service.getItem('test');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be called setItem', () => {
|
||||
const spy = jest.spyOn(service, 'setItem');
|
||||
service.setItem('test', 'value');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be called removeItem', () => {
|
||||
const spy = jest.spyOn(service, 'removeItem');
|
||||
service.removeItem('test');
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be called clear', () => {
|
||||
const spy = jest.spyOn(service, 'clear');
|
||||
service.clear();
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be called key', () => {
|
||||
const spy = jest.spyOn(service, 'key');
|
||||
service.key(0);
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it('should be called length', () => {
|
||||
const spy = jest.spyOn(service, 'length', 'get');
|
||||
service.length;
|
||||
expect(spy).toHaveBeenCalled();
|
||||
});
|
||||
});
|
Loading…
Reference in new issue