Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature(oidc):add oidc readme、fix list removeRange error bug #109

Merged
merged 9 commits into from
Jun 30, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
[中](README.zh-CN.md) | EN

## Masa.Contrib.Authentication.Oidc.Cache.Storage

Effect:

Use IClientStore and IResourceStore get oidc resources and client data.

```c#
├── IClientStore
├── IResourceStore
```

Example:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.Cache.Storage
```

```C#
builder.Services.AddOidcCacheStorage(nnew RedisConfigurationOptions
{
Servers = new List<RedisServerOptions>
{
new RedisServerOptions
{
Host="127.0.0.1",
Port=6379
}
},
DefaultDatabase = 0,
Password = "",
});
```

How to use:

```c#
var app = builder.Build();

app.MapGet("/GetClient", async ([FromServices] IClientStore store) =>
{
return await store.FindClientByIdAsync("clientId");
});

app.Run();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
中 | [EN](README.md)

## Masa.Contrib.Authentication.Oidc.Cache.Storag

作用:

通过IClientStore和IResourceStore获取资源和客户端的相关数据

```c#
├── IClientStore
├── IResourceStore
```

用例:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.Cache.Storag
```

```C#
builder.Services.AddOidcCacheStorage(nnew RedisConfigurationOptions
{
Servers = new List<RedisServerOptions>
{
new RedisServerOptions
{
Host="127.0.0.1",
Port=6379
}
},
DefaultDatabase = 0,
Password = "",
});
```

如何使用:

```c#
var app = builder.Build();

app.MapGet("/GetClient", async ([FromServices] IClientStore store) =>
{
return await store.FindClientByIdAsync("clientId");
});

app.Run();
```
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,13 @@ public ClientCache(IMemoryCacheClient memoryCacheClient)
return await _memoryCacheClient.GetAsync<ClientModel>(FormatKey(clientId));
}

public async Task<List<ClientModel>> GetListAsync(IEnumerable<string> clientIds)
{
var keys = clientIds.Select(clientId => FormatKey(clientId)).ToArray();
var clients = await _memoryCacheClient.GetListAsync<ClientModel>(keys);
return clients.Where(client => client is not null).ToList()!;
}

public async Task SetAsync(Client client)
{
await _memoryCacheClient.SetAsync(FormatKey(client), client.ToModel());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
[中](README.zh-CN.md) | EN

## Masa.Contrib.Authentication.Oidc.Cache

Effect:

Use the second level cache to operate resources and client data.

```c#
├── ApiResourceCache
├── ApiScopeCache
├── ClientCache
├── IdentityResourceCache
```

Example:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.Cache
```

```C#
builder.Services.AddOidcCache(nnew RedisConfigurationOptions
{
Servers = new List<RedisServerOptions>
{
new RedisServerOptions
{
Host="127.0.0.1",
Port=6379
}
},
DefaultDatabase = 0,
Password = "",
});
```

How to use:

```c#
var app = builder.Build();

app.MapGet("/GetClient", async ([FromServices] IClientCache cache) =>
{
return await cache.GetAsync("clientId");
});

app.Run();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
中 | [EN](README.md)

## Masa.Contrib.Authentication.Oidc.Cache

作用:

使用二级缓存来操作资源和客户端数据。

```c#
├── ApiResourceCache
├── ApiScopeCache
├── ClientCache
├── IdentityResourceCache
```

用例:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.Cache
```

```C#
builder.Services.AddOidcCache(nnew RedisConfigurationOptions
{
Servers = new List<RedisServerOptions>
{
new RedisServerOptions
{
Host="127.0.0.1",
Port=6379
}
},
DefaultDatabase = 0,
Password = "",
});
```

如何使用:

```c#
var app = builder.Build();

app.MapGet("/GetClient", async ([FromServices] IClientCache cache) =>
{
return await cache.GetAsync("clientId");
});

app.Run();
```
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public static void Remove<T>(this ICollection<T> collection, T data, Func<T, obj

public static void RemoveRange<T>(this ICollection<T> collection, IEnumerable<T> datas, Func<T, object> keySelector)
{
var oldDatas = collection.Where(item => datas.Any(data => keySelector(data).Equals(keySelector(item))));
var oldDatas = collection.Where(item => datas.Any(data => keySelector(data).Equals(keySelector(item)))).ToList();
if (oldDatas.Count() > 0)
{
foreach (var oldData in oldDatas)
Expand All @@ -40,7 +40,7 @@ public static void RemoveRange<T>(this ICollection<T> collection, IEnumerable<T>

public static void Remove<T>(this ICollection<T> collection, Func<T, bool> condition)
{
var datas = collection.Where(condition);
var datas = collection.Where(condition).ToList();
if(datas.Count() > 0)
{
foreach (var data in datas)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ public class SyncCache
IApiResourceCache _apiResourceCache;
IApiScopeCache _apiScopeCache;
IIdentityResourceCache _identityResourceCache;
OidcDbContext _context;
DbContext _context;

public SyncCache(IClientCache clientCache, IApiResourceCache apiResourceCache, IApiScopeCache apiScopeCache, IIdentityResourceCache identityResourceCache, OidcDbContext context)
{
_clientCache = clientCache;
_apiResourceCache = apiResourceCache;
_apiScopeCache = apiScopeCache;
_identityResourceCache = identityResourceCache;
_context = context;
_context = context.Dbcontext;
}

internal async Task SyncApiResourceCacheAsync(int id)
Expand Down Expand Up @@ -56,7 +56,7 @@ internal async Task RemoveIdentityResourceCacheAsync(IdentityResource identityRe
await _identityResourceCache.RemoveAsync(identityResource);
}

private async Task ResetAsync()
public async Task ResetAsync()
{
var clients = await ClientQuery().ToListAsync();
var apiScopes = await ApiScopeQuery().ToListAsync();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,17 @@

namespace Masa.Contrib.Authentication.Oidc.EntityFrameworkCore.DbContexts;

public class OidcDbContext : DbContext
public class OidcDbContext
{
public OidcDbContext(DbContextOptions<OidcDbContext> options) : base(options)
public DbContext Dbcontext { get; set; }

public OidcDbContext(DbContext dbcontext)
{
Dbcontext = dbcontext;
}

protected override void OnModelCreating(ModelBuilder modelBuilder)
public static implicit operator DbContext(OidcDbContext context)
{
modelBuilder.HasDefaultSchema("oidc");
modelBuilder.ApplyConfigurationsFromAssembly(typeof(OidcDbContext).Assembly);
return context.Dbcontext;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[中](README.zh-CN.md) | EN

## Masa.Contrib.Authentication.Oidc.EntityFrameworkCore

Effect:

Use the Repository to operate the Oidc database

```c#
├── ApiResourceRepository
├── ApiScopeRepository
├── ClientRepository
├── IdentityResourceRepository
├── UserClaimRepository
```

Example:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.EntityFrameworkCore
```

```C#
builder.Services.AddOidcDbContext(option => option.UseSqlServer("ConnectionString",
b => b.MigrationsAssembly(migrationsAssembly)));
```

How to use:

```c#
var app = builder.Build();

app.MapGet("/GetClients", async ([FromServices] IClientRepository repository) =>
{
return await repository.GetListAsync();
});

app.Run();
```
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
中 | [EN](README.md)

## Masa.Contrib.Authentication.Oidc.EntityFrameworkCore

作用:

通过Repository操作Oidc数据库

```c#
├── ApiResourceRepository
├── ApiScopeRepository
├── ClientRepository
├── IdentityResourceRepository
├── UserClaimRepository
```

用例:

```C#
Install-Package Masa.Contrib.Authentication.Oidc.EntityFrameworkCore
```

```C#
builder.Services.AddOidcDbContext(option => option.UseSqlServer("ConnectionString",
b => b.MigrationsAssembly(migrationsAssembly)));
```

如何使用:

```c#
var app = builder.Build();

app.MapGet("/GetClients", async ([FromServices] IClientRepository repository) =>
{
return await repository.GetListAsync();
});

app.Run();
```
Loading