Skip to content

Commit d9540e9

Browse files
committed
Switch to use session based API Keys
1 parent bfdabfb commit d9540e9

File tree

5 files changed

+374
-102
lines changed

5 files changed

+374
-102
lines changed

AiServer/Configure.AppHost.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -149,11 +149,11 @@ public override void Configure()
149149
];
150150

151151
// Avoid having to re-renter AuthSecret and API Keys during Development
152-
PreRequestFilters.Add((req, res) =>
153-
{
154-
req.Items[Keywords.AuthSecret] = Config.AdminAuthSecret;
155-
req.Items[Keywords.Authorization] = "Bearer " + Config.AdminAuthSecret;
156-
});
152+
// PreRequestFilters.Add((req, res) =>
153+
// {
154+
// req.Items[Keywords.AuthSecret] = Config.AdminAuthSecret;
155+
// req.Items[Keywords.Authorization] = "Bearer " + Config.AdminAuthSecret;
156+
// });
157157
#endif
158158
}
159159
}

AiServer/Configure.Auth.cs

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
using AiServer.ServiceInterface;
2-
using ServiceStack.Auth;
1+
using ServiceStack.Auth;
2+
using AiServer.ServiceInterface;
33

44
[assembly: HostingStartup(typeof(ConfigureAuth))]
55

@@ -10,14 +10,17 @@ public class ConfigureAuth : IHostingStartup
1010
public void Configure(IWebHostBuilder builder) => builder
1111
.ConfigureServices(services =>
1212
{
13-
services.AddPlugin(new AuthFeature(new AuthSecretAuthProvider(AppConfig.Instance.AuthSecret)));
13+
services.AddPlugin(new AuthFeature([
14+
new ApiKeyCredentialsProvider(),
15+
new AuthSecretAuthProvider(AppConfig.Instance.AuthSecret),
16+
]));
17+
services.AddPlugin(new SessionFeature());
1418
services.AddPlugin(new ApiKeysFeature {
15-
1619
});
1720
})
1821
.ConfigureAppHost(appHost =>
1922
{
2023
using var db = HostContext.AppHost.GetDbConnection();
2124
appHost.GetPlugin<ApiKeysFeature>().InitSchema(db);
2225
});
23-
}
26+
}

AiServer/wwwroot/admin/index.html

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,9 @@
5050
</ul>
5151
</li>
5252
<li class="-mx-6 mt-auto">
53-
<div v-if="showUserMenu" class="font-normal absolute z-10 -mt-10 left-6 w-60 origin-top-right rounded-md bg-white dark:bg-black py-1 shadow-lg ring-1 ring-black dark:ring-gray-600 ring-opacity-5 focus:outline-none right-2" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1">
53+
<div v-if="showUserMenu" class="font-normal absolute z-10 -mt-16 left-6 w-60 origin-top-right rounded-md bg-white dark:bg-black py-1 shadow-lg ring-1 ring-black dark:ring-gray-600 ring-opacity-5 focus:outline-none right-2" role="menu" aria-orientation="vertical" aria-labelledby="user-menu-button" tabindex="-1">
5454
<a href="/admin/?clear=metadata" class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800" role="menuitem" tabindex="-1">Reset Cache</a>
55+
<a href="/auth/logout" class="block px-4 py-2 text-sm text-gray-700 dark:text-gray-200 hover:bg-gray-100 dark:hover:bg-gray-800" role="menuitem" tabindex="-1">Logout</a>
5556
</div>
5657
<span v-if="user" @click="showUserMenu=!showUserMenu" class="flex cursor-pointer bg-gray-50 items-center gap-x-4 px-6 py-3 text-sm font-semibold leading-6 text-gray-900 hover:bg-gray-50">
5758
<img class="h-8 w-8 rounded-full bg-gray-50" :src="user.profileUrl" alt="">
@@ -372,8 +373,12 @@ <h4 class="mt-4 font-semibold text-gray-500">By Month</h4>
372373
async function doSignIn() {
373374
authError.value = ''
374375
if (!authSecret.value) return
375-
serviceClient.headers.set("authsecret", authSecret.value)
376-
const api = await serviceClient.api(new Authenticate())
376+
// serviceClient.headers.set("authsecret", authSecret.value)
377+
const api = await serviceClient.api(new Authenticate({
378+
provider: 'credentials',
379+
userName: 'Admin',
380+
password: authSecret.value,
381+
}))
377382
if (api.succeeded) {
378383
signIn(api.response)
379384
} else {

AiServer/wwwroot/css/app.css

Lines changed: 8 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -1081,14 +1081,14 @@ select{
10811081
margin-top: -0.25rem;
10821082
}
10831083

1084-
.-mt-10 {
1085-
margin-top: -2.5rem;
1086-
}
1087-
10881084
.-mt-12 {
10891085
margin-top: -3rem;
10901086
}
10911087

1088+
.-mt-16 {
1089+
margin-top: -4rem;
1090+
}
1091+
10921092
.-mt-8 {
10931093
margin-top: -2rem;
10941094
}
@@ -2002,6 +2002,10 @@ select{
20022002
border-color: rgb(79 70 229 / var(--tw-border-opacity));
20032003
}
20042004

2005+
.border-indigo-600\/25 {
2006+
border-color: rgb(79 70 229 / 0.25);
2007+
}
2008+
20052009
.border-red-300 {
20062010
--tw-border-opacity: 1;
20072011
border-color: rgb(252 165 165 / var(--tw-border-opacity));
@@ -2031,47 +2035,6 @@ select{
20312035
border-color: rgb(250 204 21 / var(--tw-border-opacity));
20322036
}
20332037

2034-
.border-gray-900 {
2035-
--tw-border-opacity: 1;
2036-
border-color: rgb(17 24 39 / var(--tw-border-opacity));
2037-
}
2038-
2039-
.border-gray-50 {
2040-
--tw-border-opacity: 1;
2041-
border-color: rgb(249 250 251 / var(--tw-border-opacity));
2042-
}
2043-
2044-
.border-slate-100 {
2045-
--tw-border-opacity: 1;
2046-
border-color: rgb(241 245 249 / var(--tw-border-opacity));
2047-
}
2048-
2049-
.border-indigo-200 {
2050-
--tw-border-opacity: 1;
2051-
border-color: rgb(199 210 254 / var(--tw-border-opacity));
2052-
}
2053-
2054-
.border-indigo-300 {
2055-
--tw-border-opacity: 1;
2056-
border-color: rgb(165 180 252 / var(--tw-border-opacity));
2057-
}
2058-
2059-
.border-indigo-600\/50 {
2060-
border-color: rgb(79 70 229 / 0.5);
2061-
}
2062-
2063-
.border-indigo-600\/20 {
2064-
border-color: rgb(79 70 229 / 0.2);
2065-
}
2066-
2067-
.border-indigo-600\/40 {
2068-
border-color: rgb(79 70 229 / 0.4);
2069-
}
2070-
2071-
.border-indigo-600\/25 {
2072-
border-color: rgb(79 70 229 / 0.25);
2073-
}
2074-
20752038
.bg-\[\#f4f4f4\] {
20762039
--tw-bg-opacity: 1;
20772040
background-color: rgb(244 244 244 / var(--tw-bg-opacity));
@@ -3005,18 +2968,6 @@ select{
30052968
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
30062969
}
30072970

3008-
.shadow-md {
3009-
--tw-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
3010-
--tw-shadow-colored: 0 4px 6px -1px var(--tw-shadow-color), 0 2px 4px -2px var(--tw-shadow-color);
3011-
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
3012-
}
3013-
3014-
.shadow-inner {
3015-
--tw-shadow: inset 0 2px 4px 0 rgb(0 0 0 / 0.05);
3016-
--tw-shadow-colored: inset 0 2px 4px 0 var(--tw-shadow-color);
3017-
box-shadow: var(--tw-ring-offset-shadow, 0 0 #0000), var(--tw-ring-shadow, 0 0 #0000), var(--tw-shadow);
3018-
}
3019-
30202971
.\!outline-none {
30212972
outline: 2px solid transparent !important;
30222973
outline-offset: 2px !important;
@@ -3031,10 +2982,6 @@ select{
30312982
outline-style: solid;
30322983
}
30332984

3034-
.outline-gray-900 {
3035-
outline-color: #111827;
3036-
}
3037-
30382985
.ring-0 {
30392986
--tw-ring-offset-shadow: var(--tw-ring-inset) 0 0 0 var(--tw-ring-offset-width) var(--tw-ring-offset-color);
30402987
--tw-ring-shadow: var(--tw-ring-inset) 0 0 0 calc(0px + var(--tw-ring-offset-width)) var(--tw-ring-color);
@@ -4486,34 +4433,6 @@ select{
44864433
display: table-cell;
44874434
}
44884435

4489-
.md\:w-96 {
4490-
width: 24rem;
4491-
}
4492-
4493-
.md\:w-\[21em\] {
4494-
width: 21em;
4495-
}
4496-
4497-
.md\:w-\[21\.5em\] {
4498-
width: 21.5em;
4499-
}
4500-
4501-
.md\:w-\[21\.25em\] {
4502-
width: 21.25em;
4503-
}
4504-
4505-
.md\:w-\[830px\] {
4506-
width: 830px;
4507-
}
4508-
4509-
.md\:w-\[230px\] {
4510-
width: 230px;
4511-
}
4512-
4513-
.md\:w-\[330px\] {
4514-
width: 330px;
4515-
}
4516-
45174436
.md\:max-w-3xl {
45184437
max-width: 48rem;
45194438
}

0 commit comments

Comments
 (0)