2016-12-27 10 views
0

Google/Facebookへの外部ログインにOWINを使用しようとしています。C#Owinの応答タイプをコードからトークンに変更してください

問題は、owinチャレンジが応答タイプをトークンからコードに変更し続けることに直面しています。これは、Googleからのエラーを返し https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=client_dim&redirect_uri=mywebsite.com&scope=scope&state=state

課題は、以下のURLを生成します。私がresponse_typeをtoken(response_type = token)に変更すると動作します。

ここでのOAuthオプション

OAuthOptions = new OAuthAuthorizationServerOptions 
     { 

      TokenEndpointPath = new PathString("/Token"), 
      Provider = new ApplicationOAuthProvider(PublicClientId), 
      AuthorizeEndpointPath = new PathString("/api/Account/ExternalLogin"), 
      AccessTokenExpireTimeSpan = TimeSpan.FromDays(14), 

      // In production mode set AllowInsecureHttp = false 
      AllowInsecureHttp = true, 


     }; 

Googleのミドルウェアの設定されています

app.UseGoogleAuthentication(new GoogleOAuth2AuthenticationOptions() 
     { 
      ClientId = "clientid", 
      ClientSecret = "client secret", 
     }); 

ここでは、チャレンジです:

var properties = new AuthenticationProperties() { AllowRefresh = true, RedirectUri="mywebsite.co.za" }; 


     Request.GetOwinContext().Authentication.Challenge(properties,LoginProvider); 

     HttpResponseMessage response = new HttpResponseMessage(HttpStatusCode.Unauthorized); 
     response.RequestMessage = Request; 
     return Task.FromResult(response); 

OWINは、一般的なMVCのAPIからの基本的な設定ですプロジェクト。

答えて

0

トークンにresponse_typeを書き換えを解決するには、次のとおりです。

GoogleOAuth2AuthenticationOptions googleOAuth2AuthenticationOptions = new GoogleOAuth2AuthenticationOptions 
     { 
      ClientId = "clientid", 
      ClientSecret = "secret", 

      Provider = new GoogleOAuth2AuthenticationProvider 
      { 
       OnApplyRedirect = context => 
       { 
        string redirect = context.RedirectUri.Replace("response_type=code", "response_type=token"); 
        context.Response.Redirect(redirect); 
       }, 

      }, 
     }; 

     app.UseGoogleAuthentication(googleOAuth2AuthenticationOptions); 

グーグルのOAuth 2.0はなぜOwin.googleプロバイダの利用response_type =コードがないトークン= response_typeを必要とする場合、それはまだ、質問を頼みます。

関連する問題