Compare commits
No commits in common. "9d5aaf1e264dcb51a73629d9d043f98b2937e526" and "c347d08e2b3868e6271082e7810601c306697f01" have entirely different histories.
9d5aaf1e26
...
c347d08e2b
|
@ -1,5 +1,4 @@
|
||||||
using AlibabaCloud.SDK.Sts20150401;
|
using Amazon.Auth.AccessControlPolicy;
|
||||||
using Amazon.Auth.AccessControlPolicy;
|
|
||||||
using Amazon.SecurityToken;
|
using Amazon.SecurityToken;
|
||||||
using AutoMapper;
|
using AutoMapper;
|
||||||
using Azure.Core;
|
using Azure.Core;
|
||||||
|
@ -22,7 +21,6 @@ using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.AspNetCore.Mvc;
|
using Microsoft.AspNetCore.Mvc;
|
||||||
using Microsoft.Extensions.Logging;
|
using Microsoft.Extensions.Logging;
|
||||||
using Microsoft.Extensions.Options;
|
using Microsoft.Extensions.Options;
|
||||||
using Org.BouncyCastle.Tls;
|
|
||||||
using RestSharp;
|
using RestSharp;
|
||||||
using RestSharp.Authenticators;
|
using RestSharp.Authenticators;
|
||||||
using System;
|
using System;
|
||||||
|
@ -184,69 +182,6 @@ namespace IRaCIS.Api.Controllers
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
#region 老项目依赖
|
|
||||||
|
|
||||||
[HttpGet("user/GenerateSTS")]
|
|
||||||
public IResponseOutput GenerateSTS([FromServices] IOptionsMonitor<ObjectStoreServiceOptions> options)
|
|
||||||
{
|
|
||||||
|
|
||||||
var ossOptions = options.CurrentValue.AliyunOSS;
|
|
||||||
|
|
||||||
var client = new Client(new AlibabaCloud.OpenApiClient.Models.Config()
|
|
||||||
{
|
|
||||||
AccessKeyId = ossOptions.AccessKeyId,
|
|
||||||
AccessKeySecret = ossOptions.AccessKeySecret,
|
|
||||||
Endpoint = "sts.cn-hangzhou.aliyuncs.com"
|
|
||||||
});
|
|
||||||
|
|
||||||
var assumeRoleRequest = new AlibabaCloud.SDK.Sts20150401.Models.AssumeRoleRequest();
|
|
||||||
// 将<YOUR_ROLE_SESSION_NAME>设置为自定义的会话名称,例如oss-role-session。
|
|
||||||
assumeRoleRequest.RoleSessionName = $"session-name-{NewId.NextGuid()}";
|
|
||||||
// 将<YOUR_ROLE_ARN>替换为拥有上传文件到指定OSS Bucket权限的RAM角色的ARN。
|
|
||||||
assumeRoleRequest.RoleArn = ossOptions.RoleArn;
|
|
||||||
//assumeRoleRequest.RoleArn = "acs:ram::1899121822495495:role/webdirect";
|
|
||||||
assumeRoleRequest.DurationSeconds = ossOptions.DurationSeconds;
|
|
||||||
var runtime = new AlibabaCloud.TeaUtil.Models.RuntimeOptions();
|
|
||||||
var response = client.AssumeRoleWithOptions(assumeRoleRequest, runtime);
|
|
||||||
var credentials = response.Body.Credentials;
|
|
||||||
|
|
||||||
var tempToken = new AliyunOSSTempToken()
|
|
||||||
{
|
|
||||||
AccessKeyId = credentials.AccessKeyId,
|
|
||||||
AccessKeySecret = credentials.AccessKeySecret,
|
|
||||||
|
|
||||||
//转为服务器时区,最后统一转为客户端时区
|
|
||||||
Expiration = TimeZoneInfo.ConvertTimeFromUtc(DateTime.Parse(credentials.Expiration), TimeZoneInfo.Local),
|
|
||||||
SecurityToken = credentials.SecurityToken,
|
|
||||||
|
|
||||||
|
|
||||||
Region = ossOptions.Region,
|
|
||||||
BucketName = ossOptions.BucketName,
|
|
||||||
EndPoint = ossOptions.EndPoint,
|
|
||||||
ViewEndpoint = ossOptions.ViewEndpoint,
|
|
||||||
PreviewEndpoint = ossOptions.PreviewEndpoint
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
// 返回STS令牌信息给前端
|
|
||||||
var stsToken = new
|
|
||||||
{
|
|
||||||
AccessKeyId = credentials.AccessKeyId,
|
|
||||||
AccessKeySecret = credentials.AccessKeySecret,
|
|
||||||
SecurityToken = credentials.SecurityToken,
|
|
||||||
Expiration = credentials.Expiration,
|
|
||||||
|
|
||||||
Region = ossOptions.Region,
|
|
||||||
BucketName = ossOptions.BucketName,
|
|
||||||
ViewEndpoint = ossOptions.ViewEndpoint,
|
|
||||||
|
|
||||||
};
|
|
||||||
|
|
||||||
return ResponseOutput.Ok(stsToken);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
#endregion
|
|
||||||
|
|
||||||
|
|
||||||
[HttpGet("User/UserRedirect")]
|
[HttpGet("User/UserRedirect")]
|
||||||
|
|
Loading…
Reference in New Issue