简体   繁体   English

使用Office365应用的Asp.Net身份验证

[英]Asp.Net Identity authentication with Office365 app

I want to know if there is a way where I can use both Asp.Net Identity with Owin and Office 365 Owin login concurrently? 我想知道是否可以同时使用OwinOffice 365 Owin登录使用Asp.Net Identity

Basically I want to create a web hook that hooks onto Users's Exchange Inbox. 基本上,我想创建一个挂钩到用户的Exchange收件箱的Web挂钩。 When these messages arrive I need to do some processing and basically send out a notification. 当这些消息到达时,我需要进行一些处理并基本上发出通知。

I'm able to successfully create an Office 365 app; 我能够成功创建Office 365应用; I have the clientId and the clientSecret both into my Web.Config file. 我将clientIdclientSecret都放入我的Web.Config文件中。

I'm using Asp.Net MVC5 and I'm able to have a view that basically has a button and it says "Click to Subscribe"..this would then ideally open the Office 365 login and my user would be presented with a Consent form. 我使用的是Asp.Net MVC5,我可以看到一个基本上带有按钮的视图,并显示“单击订阅”。然后理想情况下将打开Office 365登录名,并向我的用户显示一个同意形成。

Although when users initially login to the website I'm using Owin with Asp.Net Identity. 尽管当用户最初登录网站时,我使用的是带有Asp.Net Identity的Owin。

When I try to faciltate the Office 365 login; 当我尝试简化Office 365登录时; these two lines are returning back null . 这两行都返回null I've followed the tutorial give here on Github. 我已经按照Github上的教程进行操作了 So I'm able to hook onto to the Exchange mailbox using the Graph API. 因此,我可以使用Graph API挂接到Exchange邮箱。 But I'm having issues with the consent form? 但是我的同意书有问题吗? Any thoughts? 有什么想法吗?

These are the two lines of suspect code: 以下是两行可疑代码:

        var signInUserId = ClaimsPrincipal.Current.FindFirst(ClaimTypes.NameIdentifier).Value;
        var userObjectId = ClaimsPrincipal.Current.FindFirst("http://schemas.microsoft.com/identity/claims/objectidentifier").Value;

The signInUserId returns me back the Asp.Net UserId field according to the user. signInUserId根据用户向我返回Asp.Net UserId字段。 I have a feeling I am doing something utterly stupid & incomplete. 我感觉自己在做一些完全愚蠢和不完整的事情。

In this scenario you sort of have two approaches to consider. 在这种情况下,您需要考虑两种方法。

  • You can set up OWIN to use OpenIDConnectAuthentication and when the user clicks subscribe, you issue a Challenge from your app. 您可以将OWIN设置为使用OpenIDConnectAuthentication并且当用户单击“订阅”时,您将从应用程序中发出Challenge OWIN will redirect the user to login, consent, and then return back to your application. OWIN将重定向用户以登录,同意,然后返回到您的应用程序。 You can then use the notifications available in the middleware to capture the authorization code, exchange it for an access token, and cache the tokens for later use. 然后,您可以使用中间件中可用的通知来捕获授权代码,将其交换为访问令牌,并缓存令牌以备后用。 This code sample shows how to do so. 此代码示例显示了如何执行此操作。 The key is to terminate the auth pipeline by calling HandleResponse() from within the notification, which will stop the OpenIDConnect sign-in pipeline and leave the ASP.NET identity in-tact. 关键是通过从通知中调用HandleResponse()来终止auth管道,这将停止OpenIDConnect登录管道,并保持ASP.NET身份完整。
  • You can craft an OAuth request yourself, without using the OWIN pipeline to trigger & catch the request/response. 您可以自己编写OAuth请求,而无需使用OWIN管道来触发和捕获请求/响应。 This sample shows you how to do so using the ADAL library. 本示例向您展示如何使用ADAL库来执行此操作。 I recommend this approach, it's a bit more straightforward. 我推荐这种方法,它更简单一些。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在 asp.net C# 中使用启用双重身份验证的 office365 email 帐户发送 email? - How to send email using two factor authentication enabled office365 email account in asp.net C#? 没有Active Directory的来自ASP.NET应用程序的Office365 SSO - Office365 SSO from ASP.NET application with no Active Directory Asp.net MVC5 和 SMTP Office365 版本 4.5.2 出现异常,代码在版本 4.8 上运行良好 - Asp.net MVC5 with SMTP Office365 Exception at version 4.5.2, the code works well at version 4.8 使用 Identity Server 对 ASP.NET Web App 和 .NET 进行身份验证 6 - Using Identity Server for Authentication with ASP.NET Web App and .NET 6 有没有一种方法可以将Office365用作WebSite的身份验证源SSO? - Is there a way to use Office365 as the authentication source SSO for a WebSite? 无需验证即可获取Office365电子邮件的日历 - Get calendars of office365 email without authentication 在asp.net中读取/写入Office 365文档 - Read / Write Office 365 document in asp.net 如何在 ASP.Net IIdentityMessageService 中使用 SMTP 或 Office 365 帐户? - How to use SMTP or Office 365 account in ASP.Net IIdentityMessageService? Office 365与Asp.net Web应用程序(MVC应用程序)集成吗? - Office 365 integration with Asp.net web application (MVC Application)? 从Office 365单一登录到Asp.Net网站 - Single sign on from office 365 to Asp.Net website
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM