小编Tom*_*SFT的帖子

在ASP.NET Core 2.0中使用Azure Active Directory OAuth和身份模型

问题陈述

我们正在开发新的企业级应用程序,并希望利用Azure Active Directory登录应用程序,以便我们不必创建另一组用户凭据.但是,我们对此应用程序的权限模型比通过AAD内部的组处理的更复杂.

那个想法

我们的想法是,除了ASP.NET核心标识框架之外,我们还可以使用Azure Active Directory OAuth 2.0来强制用户通过Azure Active Directory进行身份验证,然后使用身份框架来处理授权/权限.

问题

您可以使用Azure OpenId身份验证创建项目开箱即用,然后您可以使用Identity框架轻松地将Microsoft帐户身份验证(非AAD)添加到任何项目.但是没有内置的东西可以将AAD的OAuth添加到身份模型中.

在尝试破解这些方法以使它们像我需要的那样工作之后,我终于尝试了自己创建自己的解决方案并建立了类OAuthHandlerOAuthOptions类.

我在这条路线上遇到了很多问题,但设法解决了大部分问题.现在我到了一个点,我从端点获得一个令牌,但我的ClaimsIdentity似乎没有效果.然后,当重定向到ExternalLoginCallback时,我的SigninManager无法获取外部登录信息.

几乎肯定必须有一些我想念的简单但我似乎无法确定它是什么.

代码

Startup.cs

services.AddAuthentication()
.AddAzureAd(options =>
{
    options.ClientId = Configuration["AzureAd:ClientId"];
    options.AuthorizationEndpoint = $"{Configuration["AzureAd:Instance"]}{Configuration["AzureAd:TenantId"]}/oauth2/authorize";
    options.TokenEndpoint = $"{Configuration["AzureAd:Instance"]}{Configuration["AzureAd:TenantId"]}/oauth2/token";
    options.UserInformationEndpoint = $"{Configuration["AzureAd:Instance"]}{Configuration["AzureAd:TenantId"]}/openid/userinfo";
    options.Resource = Configuration["AzureAd:ClientId"];
    options.ClientSecret = Configuration["AzureAd:ClientSecret"];
    options.CallbackPath = Configuration["AzureAd:CallbackPath"];
});
Run Code Online (Sandbox Code Playgroud)

AzureADExtensions

namespace Microsoft.AspNetCore.Authentication.AzureAD
{
    public static class AzureAdExtensions
    {
        public static AuthenticationBuilder AddAzureAd(this AuthenticationBuilder builder)
            => builder.AddAzureAd(_ => { });

        public static AuthenticationBuilder AddAzureAd(this AuthenticationBuilder builder, Action<AzureAdOptions> configureOptions)
        {
            return …
Run Code Online (Sandbox Code Playgroud)

c# oauth azure azure-active-directory asp.net-core

10
推荐指数
1
解决办法
2053
查看次数

Azure功能临时存储

当我尝试将文件保存到Azure Functions目录(D:\home\data\temp\response.pdf)中的Temp存储时,出现以下错误.为什么我不能写到这个目录?

mscorlib: Exception has been thrown by the target of an invocation. System: An exception occurred during a WebClient request. mscorlib: ***Could not find a part of the path 'D:\home\data\temp\response.pdf'.***
2017-09-19T07:05:24.353 Function completed (Failure, Id=3aa4b740-ba8a-465c-ad7c-75b38fa2a472, Duration=334ms)
2017-09-19T07:06:31  No new trace in the past 1 min(s).
Run Code Online (Sandbox Code Playgroud)

azure azure-web-sites azure-functions

9
推荐指数
3
解决办法
4826
查看次数

如何使用Azure App Service/Web App限制IP地址

web.config中的ipSecurity部分是否适用于Azure App Services?

使用托管在Azure上的Web应用程序设置简单IP地址阻止(黑名单)的步骤是什么?

iis ip azure azure-web-sites

8
推荐指数
2
解决办法
7601
查看次数

F#,实体框架和可空值

这是F#中一个极其困难的问题,在C#中非常容易

我正在使用自定义DomainManager在F#中编写Azure移动应用程序表控制器.该DomainManager所继承MappedEntityDomainManager<,>,它采用Automapper在幕后来映射我的数据库对象转换成适合移动设备的记录.

Automapper配置文件如下所示:

type EventOrganiserProfile() =
    inherit Profile()
    do
        let nullDateTime = Nullable<DateTime>()
        base.CreateMap<MyDbEntity, MyMobileDto>() 
            ...
            .ForMember(fun dest -> dest.UpdatedAt, fun opt -> opt.MapFrom(fun src -> if src.CancelledUtc <> nullDateTime then src.CancelledUtc.Value else src.StartedUtc))
            ...
        |> ignore         
        base.CreateMap<MyMobileDto, MyDbEntity>() 
            ...
        |> ignore       
Run Code Online (Sandbox Code Playgroud)

src.StartedUtc是一个DateTime,src.CancelledUtc是一个可空的DateTime,因为它的类继承自的EntityData,dest.UpdatedAt是一个可空的DateTimeOffset.

此代码编译,但当我尝试运行它时,我收到错误消息

System.NotSupportedException:'LINQ to Entities无法识别方法'System.DateTime Invoke(System.Nullable`1 [System.DateTime])'方法,并且此方法无法转换为商店表达式.

这似乎指的是我对.Value财产的使用Nullable<DateTime>.根本原因是F#严格的类型检查.在C#中,这将由空合并运算符无缝处理??.

有没有办法模拟空合并作为F#中实体框架友好表达式的一部分?

f# entity-framework

7
推荐指数
0
解决办法
282
查看次数

Azure资源管理器 - 获取资源组的所有资源

昨天,我在Microsoft.Azure.Management.ResourceManager的1.5.0版预览中使用了这行代码:

var listResources = 
ResourceManagementClient.ResourceGroups.ListResources(resourceGroup.Name);
Run Code Online (Sandbox Code Playgroud)

今天,我已经更新到1.6.0版预览版,但是这个功能似乎不再可用了.是否有其他方法可以获取资源组中包含的资源列表?

c# azure azure-sdk-.net azure-resource-manager

7
推荐指数
1
解决办法
1517
查看次数

Cosmos DB Mongo API如何管理“请求率过高”条件

我有以下代码。

async function bulkInsert(db, collectionName, documents) {
  try {
    const cosmosResults = await db.collection(collectionName).insertMany(documents);
    console.log(cosmosResults);
    return cosmosResults
  } catch (e) {
    console.log(e)
  }

}
Run Code Online (Sandbox Code Playgroud)

如果我使用大量文档来运行它,我会得到(并非意外)

{ MongoError: Message: {"Errors":["Request rate is large"]}
  ActivityId: b3c83c38-0000-0000-0000-000000000000, 
  Request URI: /apps/DocDbApp/services/DocDbServer24/partitions/a4cb4964-38c8-11e6-8106-8cdcd42c33be/replicas/1p/, 
  RequestStats: , SDK: Microsoft.Azure.Documents.Common/1.19.102.5
    at G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:596:61
at authenticateStragglers (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:514:16)
at Connection.messageHandler (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\pool.js:550:5)
at emitMessageHandler (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\connection.js:309:10)
at TLSSocket.<anonymous> (G:\Node-8\NodeExample\node_modules\oracle-movie-ticket-demo\node_modules\mongodb-core\lib\connection\connection.js:452:17)
at emitOne (events.js:116:13)
at TLSSocket.emit (events.js:211:7)
at addChunk (_stream_readable.js:263:12)
at readableAddChunk (_stream_readable.js:250:11)
at TLSSocket.Readable.push (_stream_readable.js:208:10)
name: 'MongoError',
message: 'Message: {"Errors":["Request rate is large"]}\r\nActivityId: b3c83c38-0000-0000-0000-000000000000, 
Request …
Run Code Online (Sandbox Code Playgroud)

javascript azure mongodb node.js azure-cosmosdb

7
推荐指数
1
解决办法
2564
查看次数

如何在Azure功能中定义Azure Blob存储触发器的路径

有没有办法在没有定义具体容器的情况下触发Azure功能?

我期待,下面的函数将被触发任何容器中的任何文件.文件和容器的名称应该是变量.

*****function.json:
{
 "bindings": [
   {
    "type": "blobTrigger",
    "name": "myBlob",
    "path": "{container}/{name}",
    "connection": "AzureWebJobsStorage",
    "direction": "in"
   }
],
 "disabled": false
}

*****run.csx:
public static void Run(Stream myBlob, string name, string container, TraceWriter log, out string outputSbMsg)
{
    log.Info("C# Blob trigger function Processed blob");
    log.Info(name);
    log.Info(container);      
}
Run Code Online (Sandbox Code Playgroud)

但是,什么也没有触发.知道什么是错的吗?

azure azure-blob-storage azure-functions

6
推荐指数
1
解决办法
2992
查看次数

如何从 azure sql db 创建 BAK 文件

我想将我的 azure sql db 移动到另一台主机。但是我的新主机只允许导入 sql db 备份文件 (.BAK);我发现了如何使用 SQL Server Management Studio 生成 .BACPAK 文件,但我找不到从我的 azure sql db 创建 BAK 文件的方法。请帮忙。

sql-server azure azure-sql-server

6
推荐指数
1
解决办法
7951
查看次数

如何使用RBAC API获取所有角色分配的列表

我正在向以下API发出GET请求

https://management.azure.com/subscriptions/{{subscriptionId}}/providers/Microsoft.Authorization/roleAssignments?api-version=2017-10-01-preview
Run Code Online (Sandbox Code Playgroud)

这给了我以下的响应格式

{
            "properties": {
                "roleDefinitionId": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31/providers/Microsoft.Authorization/roleDefinitions/b24988ac-6180-42a0-ab88-20f7382dd24c",
                "principalId": "fdef6f38-b48f-4358-8482-b243ea935082",
                "principalType": "User",
                "scope": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31/resourceGroups/GE-RGrp-Kentico",
                "createdOn": "2017-08-21T11:38:53.7973201Z",
                "updatedOn": "2017-08-21T11:38:53.7973201Z",
                "createdBy": "f418e9e8-becc-41d8-ab47-66a4c50403b5",
                "updatedBy": "f418e9e8-becc-41d8-ab47-66a4c50403b5"
            },
            "id": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31/resourceGroups/GE-RGrp-Kentico/providers/Microsoft.Authorization/roleAssignments/5e6caac9-c5fd-42f0-86c6-9e96b127be51",
            "type": "Microsoft.Authorization/roleAssignments",
            "name": "5e6caac9-c5fd-42f0-86c6-9e96b127be51"
        }
Run Code Online (Sandbox Code Playgroud)

但是,当我执行CLI调用时,我会得到以下响应

> az  role assignment list

{
    "id": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31/providers/Microsoft.Authorization/roleAssignments/4096c146-b6f8-4f92-a700-a47742a5b321",
    "name": "4096c146-b6f8-4f92-a700-a47742a5b321",
    "properties": {
      "additionalProperties": {
        "createdBy": "c2024d65-cf17-45fd-b34b-09cd5c21cac7",
        "createdOn": "2017-11-07T22:03:12.4998370Z",
        "updatedBy": "c2024d65-cf17-45fd-b34b-09cd5c21cac7",
        "updatedOn": "2017-11-07T22:03:12.4998370Z"
      },
      "principalId": "780925c0-a487-4529-9eb2-837aa67a4d8a",
      "principalName": "xcavanap@genesisenergy.co.nz",
      "roleDefinitionId": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31/providers/Microsoft.Authorization/roleDefinitions/fb1c8493-542b-48eb-b624-b4c8fea62acd",
      "roleDefinitionName": "Security Admin",
      "scope": "/subscriptions/5a9c0639-4045-4c23-8418-fc091e8d1e31"
    },
Run Code Online (Sandbox Code Playgroud)

上面的回应确实有

"roleDefinitionName": "Security Admin"

但我希望通过API获得相同的响应,请帮助!!

api rbac azure azure-active-directory

6
推荐指数
1
解决办法
1626
查看次数

Azure 应用服务 - 写入文件系统 - ASP.NET Web 应用程序

我有一个在 Visual Studio 2017 中创建的 ASP.NET Web 应用程序。

在应用程序中有一个表单,用户可以在其中上传文件。上传文件后,我会处理它们并将它们保存在文件系统中:

var photo = Request.Files["file"];
photo.SaveAs("D:\\home");
Run Code Online (Sandbox Code Playgroud)

一切都在本地完美运行,但是当我在 Azure 应用服务上部署应用程序时它不起作用。

我读到,在 Azure 上,路径

D:\home
Run Code Online (Sandbox Code Playgroud)

应该是可写的。

但是当我尝试代码时,我收到此错误:

Access to the path 'd:\home\test_image.JPG' is denied.
Run Code Online (Sandbox Code Playgroud)

asp.net file-io azure azure-web-app-service

5
推荐指数
2
解决办法
6470
查看次数