문제

여기에 이상한 일이 일어나고 있습니다.

ASP.NET MVC5 웹 사이트를 만들었으며 ASP.NET ID를 통해 로컬 계정이 잘 작동합니다.

이제 외부 인증을 사용하도록 노력하고 있지만 이상한 일이 일어나고 있습니다.

나는 적당한 단계를 따랐다. 나는 이것을 내 startup.auth.cs :

    public void ConfigureAuth(IAppBuilder app)
    {
        // Enable the application to use a cookie to store information for the signed in user
        app.UseCookieAuthentication(new CookieAuthenticationOptions
        {
            AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie,
            LoginPath = new PathString("/Account/Login")
        });
        // Use a cookie to temporarily store information about a user logging in with a third party login provider
        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);

        // Uncomment the following lines to enable logging in with third party login providers
        //app.UseMicrosoftAccountAuthentication(
        //    clientId: "",
        //    clientSecret: "");

        //app.UseTwitterAuthentication(
        //   consumerKey: "",
        //   consumerSecret: "");

        //app.UseFacebookAuthentication(
        //   appId: "",
        //   appSecret: "");

        app.UseGoogleAuthentication();
    }
.

사용자가 Google과 로그온 할 링크를 클릭하면 externalLogin 메서드가 호출됩니다.

    [HttpPost]
    [AllowAnonymous]
    [ValidateAntiForgeryToken]
    public ActionResult ExternalLogin(string provider, string returnUrl)
    {
        // Request a redirect to the external login provider
        return new ChallengeResult(provider, Url.Action("ExternalLoginCallback", "Account", new { ReturnUrl = returnUrl }));
    }
. 디버깅을 통해 확인 된

도전자의 executeResult 메서드로 확인되었습니다.

        public override void ExecuteResult(ControllerContext context)
        {
            var properties = new AuthenticationProperties() { RedirectUri = RedirectUri };
            if (UserId != null)
            {
                properties.Dictionary[XsrfKey] = UserId;
            }
            context.HttpContext.GetOwinContext().Authentication.Challenge(properties, LoginProvider);
        }
.

그러나 브라우저에서는 아무 일도 일어나지 않습니다. 방금 Google Signin 페이지로 리디렉션을 기대할 수있는 빈 페이지를 얻을 수 있습니다.

전혀 오류 가보고 된 오류가 없습니다.

다른 재미있는 것은 다른 MVC5 응용 프로그램을 만들려고 노력했지만 "객체 참조가 VS2013의 객체 인스턴스"팝업으로 설정되지 않았으며 결과 프로젝트가 일반적으로 거기에있는 계정 컨트롤러가 누락되었습니다. 기본적으로.

VS2013의 설치를 수리했는데, 업데이트 1을 다시 설치했으며 솔루션의 모든 NuGET 패키지를 업데이트했습니다.

다음에 가야 할 곳의 아이디어가 부족합니다.

업데이트 1 이것이 내 PC와 관련 될 수 있다고 생각하면 웹 사이트를 Azure에 배포했으며 문제는 여전히 지속됩니다. 이는 누락 된 조립과 관련이있을 수 있습니다. 올바르게보고되지는 않습니다. 나는 fusionlog를 실행하지만 바인딩 실패가 없음을 알 수 없습니다.

Windows 8 및 VS2013을 깨끗하게 설치하여 새로운 프로젝트를 구입할 수 있는지 확인하십시오.

업데이트 2 OK는 "네트워크"캡처의 또 다른 라운드를 실행하고 사용자가 외부 공급자를 선택하면 ExternalLogin 동작에 게시되지만 응답은 401 권한이 없습니다. 이 일을 일으킬 수있는 것은 무엇입니까?

도움이 되었습니까?

해결책

확인,

이슈의 중요한 부분 (중요한 부분)이 무엇인지 알아 냈습니다.

첫째, 나는 아직도 MVC 프로젝트를 생성 할 때 Scaffold'ed AccountController 클래스를 얻지 못한다.

그러나 내 로그인 버튼이 "Google"대신 "Google"대신 "Google"이 전달되었다는 것입니다.

진지하게!?나는 케이싱이 제공자의 이름으로 중요하지만 거기에서 당신은가는 것이 조금 놀랐습니다.

다른 팁

이것은 귀하의 질문에 대한 대답이 아니라 매우 비슷한 문제가

에 응답합니다.

OWIN 2.0이 있고 2.1

로 이주하는 경우

_ExternAlloGinSlistPartial은 다음에서 변경해야합니다.

<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="Partner" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
.

<button type="submit" class="btn btn-default" id="@p.AuthenticationType" name="provider" value="@p.AuthenticationType" title="Log in using your @p.Caption account">@p.AuthenticationType</button>
.

변경 사항은 버튼의 이름이지만 내 머리를 끊고 내 2 일 동안 문제를 찾는 데 2 일 비용이 소요될 수 있습니다.

이것은 새로운 OWIN 버전에서 설명 될 수 있습니다.

My ASP.NET WebApi 서버에서 동일한 문제로 실행되었습니다.나는 올바른 인증 유형을 챌린지 메소드로 전달했지만 여전히 빈 페이지를 얻는 중입니다.

시작시 Owin 파이프 라인에 OAuth 공급자를 추가 한 문제는 문제를 해결했습니다. 대략 내 작업 주문 :

        app.UseExternalSignInCookie(DefaultAuthenticationTypes.ExternalCookie);
        OAuthBearerOptions = new OAuthBearerAuthenticationOptions();

        var authServerOptions = new OAuthAuthorizationServerOptions
        {
        ...
        };

        // Token Generation
        app.UseOAuthAuthorizationServer(authServerOptions);
        app.UseOAuthBearerAuthentication(OAuthBearerOptions);

        // Configure Google External Login
        GoogleAuthOptions = new GoogleOAuth2AuthenticationOptions()
        {
            ClientId = xxxx,
            ClientSecret = xxxx,
            Provider = new GoogleAuthProvider()
        };
        app.UseGoogleAuthentication(GoogleAuthOptions);

        app.UseCors(Microsoft.Owin.Cors.CorsOptions.AllowAll);
        app.UseWebApi(config);
.

이전에는 UseGoOgleAuthentication 메소드를 사용하기 전에 UseCors + UseWebapi 방법을 추가했습니다.

이 게시물도 유용하게 찾았습니다. http://coding.abel.nu/2014/06 / 이해 - owin 외부 인증 - 파이프 라인 /

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top