Require API key
This commit is contained in:
parent
afdadbcd90
commit
7e66a609b5
7 changed files with 29 additions and 4 deletions
|
@ -20,11 +20,17 @@ steps:
|
||||||
from_secret: GitApiEndpoint
|
from_secret: GitApiEndpoint
|
||||||
GitApiToken:
|
GitApiToken:
|
||||||
from_secret: GitApiToken
|
from_secret: GitApiToken
|
||||||
|
AuthEndpoint:
|
||||||
|
from_secret: AuthEndpoint
|
||||||
|
AuthApiKey:
|
||||||
|
from_secret: AuthApiKey
|
||||||
commands:
|
commands:
|
||||||
- chmod +x ./build.sh
|
- chmod +x ./build.sh
|
||||||
- ./build.sh
|
- ./build.sh
|
||||||
- sed -i "s/<GitApiEndpoint>/$GitApiEndpoint/g" output/appsettings.json
|
- sed -i "s/<GitApiEndpoint>/$GitApiEndpoint/g" output/appsettings.json
|
||||||
- sed -i "s/<GitApiToken>/$GitApiToken/g" output/appsettings.json
|
- sed -i "s/<GitApiToken>/$GitApiToken/g" output/appsettings.json
|
||||||
|
- sed -i "s/<AuthEndpoint>/$AuthEndpoint/g" output/appsettings.json
|
||||||
|
- sed -i "s/<AuthApiKey>/$AuthApiKey/g" output/appsettings.json
|
||||||
- cp api.projects.service output/
|
- cp api.projects.service output/
|
||||||
- cp -r ./output/* /output
|
- cp -r ./output/* /output
|
||||||
- name: restart service
|
- name: restart service
|
||||||
|
|
|
@ -3,4 +3,6 @@
|
||||||
sed \
|
sed \
|
||||||
-e 's/"gitApiEndpoint": ".*"/"gitApiEndpoint": ""/g' \
|
-e 's/"gitApiEndpoint": ".*"/"gitApiEndpoint": ""/g' \
|
||||||
-e 's/"gitApiToken": ".*"/"gitApiToken": ""/g' \
|
-e 's/"gitApiToken": ".*"/"gitApiToken": ""/g' \
|
||||||
|
-e 's/"authEndpoint": ".*"/"authEndpoint": ""/g' \
|
||||||
|
-e 's/"authApiKey": ".*"/"authApiKey": ""/g' \
|
||||||
$1
|
$1
|
|
@ -9,5 +9,9 @@
|
||||||
<ProjectReference Include="..\Robware.Projects\Robware.Projects.csproj" />
|
<ProjectReference Include="..\Robware.Projects\Robware.Projects.csproj" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
|
||||||
|
<ItemGroup>
|
||||||
|
<PackageReference Include="Robware.Lib.Auth.ApiKey" Version="1.1.0" />
|
||||||
|
</ItemGroup>
|
||||||
|
|
||||||
|
|
||||||
</Project>
|
</Project>
|
||||||
|
|
|
@ -5,6 +5,7 @@ using Microsoft.AspNetCore.Hosting;
|
||||||
using Microsoft.Extensions.Configuration;
|
using Microsoft.Extensions.Configuration;
|
||||||
using Microsoft.Extensions.DependencyInjection;
|
using Microsoft.Extensions.DependencyInjection;
|
||||||
using Microsoft.Extensions.Hosting;
|
using Microsoft.Extensions.Hosting;
|
||||||
|
using Robware.Lib.Auth.ApiKey;
|
||||||
using Robware.Projects.Code;
|
using Robware.Projects.Code;
|
||||||
using Robware.Projects.Gogs;
|
using Robware.Projects.Gogs;
|
||||||
|
|
||||||
|
@ -24,6 +25,8 @@ namespace Robware.Api.Projects {
|
||||||
client.DefaultRequestHeaders.Add("Authorization", $"token {Configuration["gitApiToken"]}");
|
client.DefaultRequestHeaders.Add("Authorization", $"token {Configuration["gitApiToken"]}");
|
||||||
})
|
})
|
||||||
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler {ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true});
|
.ConfigurePrimaryHttpMessageHandler(() => new HttpClientHandler {ServerCertificateCustomValidationCallback = (message, cert, chain, errors) => true});
|
||||||
|
|
||||||
|
services.AddApiKeyAuthentication(Configuration["authEndpoint"], Configuration["authApiKey"]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
|
||||||
|
@ -35,11 +38,11 @@ namespace Robware.Api.Projects {
|
||||||
app.UseHttpsRedirection();
|
app.UseHttpsRedirection();
|
||||||
|
|
||||||
app.UseRouting();
|
app.UseRouting();
|
||||||
|
app.UseAuthentication();
|
||||||
app.UseAuthorization();
|
app.UseAuthorization();
|
||||||
|
|
||||||
app.UseEndpoints(endpoints => {
|
app.UseEndpoints(endpoints => {
|
||||||
endpoints.MapControllers();
|
endpoints.MapControllers().RequireAuthorization();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,5 +7,7 @@
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"gitApiEndpoint": "",
|
"gitApiEndpoint": "",
|
||||||
"gitApiToken": ""
|
"gitApiToken": "",
|
||||||
|
"authEndpoint": "",
|
||||||
|
"authApiKey": ""
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,5 +15,7 @@
|
||||||
},
|
},
|
||||||
"AllowedHosts": "*",
|
"AllowedHosts": "*",
|
||||||
"gitApiEndpoint": "<GitApiEndpoint>",
|
"gitApiEndpoint": "<GitApiEndpoint>",
|
||||||
"gitApiToken": "<GitApiToken>"
|
"gitApiToken": "<GitApiToken>",
|
||||||
|
"authEndpoint": "<AuthEndpoint>",
|
||||||
|
"authApiKey": "<AuthApiKey>"
|
||||||
}
|
}
|
||||||
|
|
6
src/nuget.config
Normal file
6
src/nuget.config
Normal file
|
@ -0,0 +1,6 @@
|
||||||
|
<configuration>
|
||||||
|
<packageSources>
|
||||||
|
<add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
|
||||||
|
<add key="Robware" value="https://nuget.robware.uk/v3/index.json" />
|
||||||
|
</packageSources>
|
||||||
|
</configuration>
|
Loading…
Add table
Add a link
Reference in a new issue