Last active
November 28, 2024 07:45
apikeys-auth
This file contains hidden or 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
dotnet add package ServiceStack.Server |
This file contains hidden or 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
using ServiceStack; | |
using ServiceStack.Auth; | |
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 AuthFeature([ | |
new ApiKeyCredentialsProvider(), | |
new AuthSecretAuthProvider("p@55wOrd"), | |
])); | |
services.AddPlugin(new SessionFeature()); | |
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", | |
// ], | |
}); | |
}) | |
.ConfigureAppHost(appHost => | |
{ | |
using var db = appHost.Resolve<IDbConnectionFactory>().Open(); | |
var feature = appHost.GetPlugin<ApiKeysFeature>(); | |
feature.InitSchema(db); | |
}); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment