fix #3669 add CORS policy and use Jwt with XHR to allow file uploads to work in .NET MAUI
This commit is contained in:
@ -131,6 +131,16 @@ namespace Oqtane
|
||||
.WithSiteIdentity()
|
||||
.WithSiteAuthentication();
|
||||
|
||||
services.AddCors(options =>
|
||||
{
|
||||
options.AddPolicy(Constants.MauiUserAgent,
|
||||
policy =>
|
||||
{
|
||||
policy.WithOrigins("https://0.0.0.0", "http://0.0.0.0", "app://0.0.0.0")
|
||||
.AllowAnyHeader().AllowCredentials();
|
||||
});
|
||||
});
|
||||
|
||||
services.AddMvc(options =>
|
||||
{
|
||||
options.Filters.Add(new AutoValidateAntiforgeryTokenAttribute());
|
||||
@ -176,6 +186,7 @@ namespace Oqtane
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
app.UseStaticFiles();
|
||||
app.UseCors(Constants.MauiUserAgent);
|
||||
app.UseTenantResolution();
|
||||
app.UseJwtAuthorization();
|
||||
app.UseBlazorFrameworkFiles();
|
||||
|
@ -284,7 +284,7 @@ Oqtane.Interop = {
|
||||
}
|
||||
return files;
|
||||
},
|
||||
uploadFiles: function (posturl, folder, id, antiforgerytoken) {
|
||||
uploadFiles: function (posturl, folder, id, antiforgerytoken, jwt) {
|
||||
var fileinput = document.getElementById('FileInput_' + id);
|
||||
var files = fileinput.files;
|
||||
var progressinfo = document.getElementById('ProgressInfo_' + id);
|
||||
@ -323,6 +323,10 @@ Oqtane.Interop = {
|
||||
data.append('formfile', Chunk, FileName);
|
||||
var request = new XMLHttpRequest();
|
||||
request.open('POST', posturl, true);
|
||||
if (jwt !== "") {
|
||||
request.setRequestHeader('Authorization', 'Bearer ' + jwt);
|
||||
request.withCredentials = true;
|
||||
}
|
||||
request.upload.onloadstart = function (e) {
|
||||
if (progressinfo !== null && progressbar !== null) {
|
||||
progressinfo.innerHTML = file.name + ' 0%';
|
||||
|
Reference in New Issue
Block a user