簡體   English   中英

salesforce owin oauth登錄返回未經授權的響應

[英]salesforce owin oauth login returns an unauthorized response

我目前正在嘗試使用owin安全提供程序對我的Web應用程序上的Salesforce用戶進行身份驗證。

更新 :通過添加salesforceOptions.CallbackPath = new PathString("/callback"); 到Startup.Auth.cs文件,我可以導航到登錄屏幕。 但是,當我輸入我的憑據時,我將返回登錄頁面。 函數AuthenticationManager.GetExternalLoginInfo(); 返回null。

Salesforce設置(樣本):
消費者密鑰= abc
消費者秘密= def
所選的OAuth范圍=基本(ID,個人資料,電子郵件,地址電話)
回調網址= http:// localhost:12345 /回調 http:// localhost:12345 / account / externallogin
啟用設備流=否
Web服務器流需要密碼= true
包括自定義屬性= false
包括自定義權限=否

創建解決方案:
我在vs 2015中創建了具有個人用戶身份驗證的MVC應用。
我添加了NugetPackage Owin.Security.Providers.Salesforce

// Startup.Auth.cs class
public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        // Generated code
        app.CreatePerOwinContext(ApplicationDbContext.Create);
        app.CreatePerOwinContext<ApplicationUserManager>(ApplicationUserManager.Create);
        app.CreatePerOwinContext<ApplicationSignInManager>(ApplicationSignInManager.Create);
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login"),
            Provider = new CookieAuthenticationProvider
            {
                OnValidateIdentity = SecurityStampValidator.OnValidateIdentity<ApplicationUserManager, ApplicationUser>(
                    validateInterval: TimeSpan.FromMinutes(30),
                    regenerateIdentity: (manager, user) => user.GenerateUserIdentityAsync(manager))
            }
        });            
       app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
       app.UseTwoFactorSignInCookie(DefaultAuthenticationTypes.TwoFactorCookie, TimeSpan.FromMinutes(5));
       app.UseTwoFactorRememberBrowserCookie(DefaultAuthenticationTypes.TwoFactorRememberBrowserCookie);

        // I added this
        var salesforceOptions = new SalesforceAuthenticationOptions
        {
            Endpoints =
               new SalesforceAuthenticationOptions.SalesforceAuthenticationEndpoints
               {
                   AuthorizationEndpoint =
                       "https://login.salesforce.com/services/oauth2/authorize",
                   TokenEndpoint = "https://login.salesforce.com/services/oauth2/token"
               },
            ClientId = "abc",
            ClientSecret = "def"
        };
        // I added the following to get one step further:
        salesforceOptions.CallbackPath =  new PathString("/callback");
        app.UseSalesforceAuthentication(salesforceOptions);
    }
}

對web.config或任何其他文件未做任何更改。 運行應用程序時,我會收到一個Salesforce登錄按鈕。 當我按下此按鈕並輸入憑據時,我將重定向到“登錄”頁面,沒有登錄詳細信息。

我期望返回我的LoginInfo的函數在帳戶控制器中:
var loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync();

我可能會缺少哪些設置?

未經授權的反應是鯡魚 它與此無關。 我在Google登錄期間收到了相同的401,但效果很好

我找到了問題的答案。 我設法在日志中找到一條隱藏的消息,告訴我以下內容:

需要更強的安全性

要訪問該網站,請更新Web瀏覽器或升級操作系統以支持TLS 1.1或TLS 1.2。

TSL =>“傳輸層安全性”。

谷歌搜索之后,我設法找到解決方案。 通過將以下行添加到啟動代碼中,我解決了問題:

using System.Net;

public partial class Startup
{
    public void ConfigureAuth(IAppBuilder app)
    {
        ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12 | SecurityProtocolType.Tls11;
        // rest of Startup.Auth.cs code
    }
}

完成后,我可以正常登錄。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM