-
Notifications
You must be signed in to change notification settings - Fork 1
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
7 changed files
with
688 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
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,17 @@ | ||
@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(), | ||
}); | ||
|
||
[CascadingParameter] | ||
private HttpContext HttpContext { get; set; } = default!; | ||
} |
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,53 @@ | ||
using MyApp.Data; | ||
using ServiceStack.Configuration; | ||
using ServiceStack.Data; | ||
using ServiceStack.OrmLite; | ||
|
||
[assembly: HostingStartup(typeof(MyApp.ConfigureApiKeys))] | ||
|
||
namespace MyApp; | ||
|
||
public class ConfigureApiKeys : IHostingStartup | ||
{ | ||
public void Configure(IWebHostBuilder builder) => builder | ||
.ConfigureServices(services => | ||
{ | ||
services.AddPlugin(new ApiKeysFeature | ||
{ | ||
Features = [ | ||
"Tracking" | ||
], | ||
|
||
// Optional: Limit scope of API Key access | ||
UserScopes = [ | ||
"todo:read", | ||
"todo:write", | ||
], | ||
// Optional: Tag API Keys with additional features | ||
UserFeatures = [ | ||
"Tracking", | ||
], | ||
}); | ||
}) | ||
.ConfigureAppHost(appHost => | ||
{ | ||
var apiKeysFeature = appHost.GetPlugin<ApiKeysFeature>(); | ||
using var db = appHost.Resolve<IDbConnectionFactory>().Open(); | ||
apiKeysFeature.InitSchema(db); | ||
|
||
// Optional, create API Key for specified Users | ||
if (apiKeysFeature.ApiKeyCount(db) == 0) | ||
{ | ||
var createApiKeysFor = new [] { "[email protected]", "[email protected]" }; | ||
var users = db.Select<ApplicationUser>(x => createApiKeysFor.Contains(x.UserName)); | ||
foreach (var user in users) | ||
{ | ||
List<string> scopes = user.UserName == "[email protected]" | ||
? [RoleNames.Admin] | ||
: []; | ||
apiKeysFeature.Insert(db, | ||
new() { Name = "Seed API Key", UserId = user.Id, UserName = user.UserName, Scopes = scopes }); | ||
} | ||
} | ||
}); | ||
} |
Oops, something went wrong.