mirror of https://github.com/abpframework/abp.git
committed by
GitHub
11 changed files with 120 additions and 87 deletions
@ -1,8 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.MauiBlazor; |
|||
|
|||
public interface IAbpMauiAccessTokenProvider |
|||
{ |
|||
Task<string> GetAccessTokenAsync(); |
|||
} |
|||
@ -0,0 +1,14 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.Authentication; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.MauiBlazor; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class MauiBlazorAbpAccessTokenProvider : IAbpAccessTokenProvider, ITransientDependency |
|||
{ |
|||
public virtual Task<string> GetTokenAsync() |
|||
{ |
|||
return Task.FromResult(null as string); |
|||
} |
|||
} |
|||
@ -1,13 +0,0 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.MauiBlazor; |
|||
|
|||
[Dependency(TryRegister = true)] |
|||
public class NullAbpMauiAccessTokenProvider : IAbpMauiAccessTokenProvider |
|||
{ |
|||
public Task<string> GetAccessTokenAsync() |
|||
{ |
|||
return Task.FromResult(null as string); |
|||
} |
|||
} |
|||
@ -0,0 +1,29 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Authentication; |
|||
using Microsoft.AspNetCore.Http; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.Authentication; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.Web; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class HttpContextAbpAccessTokenProvider : IAbpAccessTokenProvider, ITransientDependency |
|||
{ |
|||
protected IHttpContextAccessor HttpContextAccessor { get; } |
|||
|
|||
public HttpContextAbpAccessTokenProvider(IHttpContextAccessor httpContextAccessor) |
|||
{ |
|||
HttpContextAccessor = httpContextAccessor; |
|||
} |
|||
|
|||
public virtual async Task<string> GetTokenAsync() |
|||
{ |
|||
var httpContext = HttpContextAccessor?.HttpContext; |
|||
if (httpContext == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
return await httpContext.GetTokenAsync("access_token"); |
|||
} |
|||
} |
|||
@ -0,0 +1,34 @@ |
|||
using System.Threading.Tasks; |
|||
using Microsoft.AspNetCore.Components.WebAssembly.Authentication; |
|||
using Volo.Abp.DependencyInjection; |
|||
using Volo.Abp.Http.Client.Authentication; |
|||
|
|||
namespace Volo.Abp.Http.Client.IdentityModel.WebAssembly; |
|||
|
|||
[Dependency(ReplaceServices = true)] |
|||
public class WebAssemblyAbpAccessTokenProvider : IAbpAccessTokenProvider, ITransientDependency |
|||
{ |
|||
protected IAccessTokenProvider AccessTokenProvider { get; } |
|||
|
|||
public WebAssemblyAbpAccessTokenProvider(IAccessTokenProvider accessTokenProvider) |
|||
{ |
|||
AccessTokenProvider = accessTokenProvider; |
|||
} |
|||
|
|||
public virtual async Task<string> GetTokenAsync() |
|||
{ |
|||
if (AccessTokenProvider == null) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
var result = await AccessTokenProvider.RequestAccessToken(); |
|||
if (result.Status != AccessTokenResultStatus.Success) |
|||
{ |
|||
return null; |
|||
} |
|||
|
|||
result.TryGetToken(out var token); |
|||
return token.Value; |
|||
} |
|||
} |
|||
@ -0,0 +1,8 @@ |
|||
using System.Threading.Tasks; |
|||
|
|||
namespace Volo.Abp.Http.Client.Authentication; |
|||
|
|||
public interface IAbpAccessTokenProvider |
|||
{ |
|||
Task<string> GetTokenAsync(); |
|||
} |
|||
@ -0,0 +1,12 @@ |
|||
using System.Threading.Tasks; |
|||
using Volo.Abp.DependencyInjection; |
|||
|
|||
namespace Volo.Abp.Http.Client.Authentication; |
|||
|
|||
public class NullAbpAccessTokenProvider : IAbpAccessTokenProvider, ITransientDependency |
|||
{ |
|||
public Task<string> GetTokenAsync() |
|||
{ |
|||
return Task.FromResult(null as string); |
|||
} |
|||
} |
|||
Loading…
Reference in new issue