generated from NetCoreTemplates/blazor-vue
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
685 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
@page "/Account/Manage/ApiKeys" | ||
|
||
<PageTitle>Manage API Keys</PageTitle> | ||
|
||
<div> | ||
<Heading3>Manage API Keys</Heading3> | ||
<div data-component="pages/Account/Manage/ManageUserApiKeys.mjs" data-props="@ToProps()"></div> | ||
</div> | ||
|
||
@code { | ||
public MarkupString ToProps() => BlazorHtml.RawJson(new { | ||
info = HostContext.AppHost.GetPlugin<ApiKeysFeature>()?.GetApiKeyInfo(), | ||
}); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
using MyApp.Data; | ||
using ServiceStack; | ||
using ServiceStack.Data; | ||
using ServiceStack.OrmLite; | ||
using ServiceStack.Configuration; | ||
|
||
[assembly: HostingStartup(typeof(MyApp.ConfigureApiKeys))] | ||
|
||
namespace MyApp; | ||
|
||
public class ConfigureApiKeys : IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) => builder | ||
.ConfigureServices(services => | ||
{ | ||
services.AddPlugin(new ApiKeysFeature | ||
{ | ||
// Optional: Available Scopes Admin Users can assign to any API Key | ||
// Features = [ | ||
// "Paid", | ||
// "Tracking", | ||
// ], | ||
// Optional: Available Features Admin Users can assign to any API Key | ||
// Scopes = [ | ||
// "todo:read", | ||
// "todo:write", | ||
// ], | ||
// Optional: Limit available Scopes Users can assign to their own API Keys | ||
// UserScopes = [ | ||
// "todo:read", | ||
// ], | ||
// Optional: Limit available Features Users can assign to their own API Keys | ||
// UserFeatures = [ | ||
// "Tracking", | ||
// ], | ||
}); | ||
}) | ||
.ConfigureAppHost(appHost => | ||
{ | ||
using var db = appHost.Resolve<IDbConnectionFactory>().Open(); | ||
var apiKeysFeature = appHost.GetPlugin<ApiKeysFeature>(); | ||
apiKeysFeature.InitSchema(db); | ||
// Optional: Create API Key for specified Users on Startup | ||
if (apiKeysFeature.ApiKeyCount(db) == 0) | ||
{ | ||
var createApiKeysFor = new [] { "admin@email.com", "manager@email.com" }; | ||
var users = db.Select<ApplicationUser>(x => createApiKeysFor.Contains(x.UserName)); | ||
foreach (var user in users) | ||
{ | ||
List<string> scopes = user.UserName == "admin@email.com" | ||
? [RoleNames.Admin] | ||
: []; | ||
apiKeysFeature.Insert(db, | ||
new() { Name = "Seed API Key", UserId = user.Id, UserName = user.UserName, Scopes = scopes }); | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.