私は外部のログインを(Facebookへ)有効にする私のアプリケーションでASP.NETコアアイデンティティを使用しています。私の質問は、Facebookのログインページにリダイレクトされ、OKをクリックした後、FacebookによってExternalLoginCallbackメソッドにリダイレクトされた後、FacebookMiddlewareがFacebookのボタンを[ログイン]ページでクリックした後のことですFacebookMiddlewareのすべてのスキームとそれは何ですか?外部ログインでFacebookMiddlewareの役割は何ですか?
答えて
名前が言うように、FacebookMiddlewareはFacebookを使用しているユーザーを認証しているコンポーネントです。
UseFacebookAuthentication呼び出しを呼び出すと、基本的にFacebookMiddlewareが接続されます。
FacebookMiddlewareが内部で何がそう、ここで誰かが同じ問題に遭遇し念のFacebookHandler
internal class FacebookHandler : OAuthHandler<FacebookOptions>
{
public FacebookHandler(HttpClient httpClient) : base(httpClient)
{
}
protected override async Task<AuthenticationTicket> CreateTicketAsync(ClaimsIdentity identity, AuthenticationProperties properties, OAuthTokenResponse tokens)
{
string text = QueryHelpers.AddQueryString(this.get_Options().get_UserInformationEndpoint(), "access_token", tokens.get_AccessToken());
if (this.get_Options().SendAppSecretProof)
{
text = QueryHelpers.AddQueryString(text, "appsecret_proof", this.GenerateAppSecretProof(tokens.get_AccessToken()));
}
if (this.get_Options().Fields.get_Count() > 0)
{
text = QueryHelpers.AddQueryString(text, "fields", string.Join(",", this.get_Options().Fields));
}
HttpResponseMessage httpResponseMessage = await this.get_Backchannel().GetAsync(text, this.get_Context().get_RequestAborted());
if (!httpResponseMessage.get_IsSuccessStatusCode())
{
throw new HttpRequestException(string.Format("Failed to retrieve Facebook user information ({0}) Please check if the authentication information is correct and the corresponding Facebook Graph API is enabled.", httpResponseMessage.get_StatusCode()));
}
JObject jObject = JObject.Parse(await httpResponseMessage.get_Content().ReadAsStringAsync());
AuthenticationTicket authenticationTicket = new AuthenticationTicket(new ClaimsPrincipal(identity), properties, this.get_Options().get_AuthenticationScheme());
OAuthCreatingTicketContext oAuthCreatingTicketContext = new OAuthCreatingTicketContext(authenticationTicket, this.get_Context(), this.get_Options(), this.get_Backchannel(), tokens, jObject);
string id = FacebookHelper.GetId(jObject);
if (!string.IsNullOrEmpty(id))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/nameidentifier", id, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string ageRangeMin = FacebookHelper.GetAgeRangeMin(jObject);
if (!string.IsNullOrEmpty(ageRangeMin))
{
identity.AddClaim(new Claim("urn:facebook:age_range_min", ageRangeMin, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string ageRangeMax = FacebookHelper.GetAgeRangeMax(jObject);
if (!string.IsNullOrEmpty(ageRangeMax))
{
identity.AddClaim(new Claim("urn:facebook:age_range_max", ageRangeMax, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string birthday = FacebookHelper.GetBirthday(jObject);
if (!string.IsNullOrEmpty(birthday))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/dateofbirth", birthday, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string email = FacebookHelper.GetEmail(jObject);
if (!string.IsNullOrEmpty(email))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/emailaddress", email, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string firstName = FacebookHelper.GetFirstName(jObject);
if (!string.IsNullOrEmpty(firstName))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/givenname", firstName, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string gender = FacebookHelper.GetGender(jObject);
if (!string.IsNullOrEmpty(gender))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/gender", gender, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string lastName = FacebookHelper.GetLastName(jObject);
if (!string.IsNullOrEmpty(lastName))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/surname", lastName, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string link = FacebookHelper.GetLink(jObject);
if (!string.IsNullOrEmpty(link))
{
identity.AddClaim(new Claim("urn:facebook:link", link, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string location = FacebookHelper.GetLocation(jObject);
if (!string.IsNullOrEmpty(location))
{
identity.AddClaim(new Claim("urn:facebook:location", location, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string locale = FacebookHelper.GetLocale(jObject);
if (!string.IsNullOrEmpty(locale))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/locality", locale, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string middleName = FacebookHelper.GetMiddleName(jObject);
if (!string.IsNullOrEmpty(middleName))
{
identity.AddClaim(new Claim("urn:facebook:middle_name", middleName, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string name = FacebookHelper.GetName(jObject);
if (!string.IsNullOrEmpty(name))
{
identity.AddClaim(new Claim("http://schemas.xmlsoap.org/ws/2005/05/identity/claims/name", name, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
string timeZone = FacebookHelper.GetTimeZone(jObject);
if (!string.IsNullOrEmpty(timeZone))
{
identity.AddClaim(new Claim("urn:facebook:timezone", timeZone, "http://www.w3.org/2001/XMLSchema#string", this.get_Options().get_ClaimsIssuer()));
}
await this.get_Options().get_Events().CreatingTicket(oAuthCreatingTicketContext);
return oAuthCreatingTicketContext.get_Ticket();
}
private string GenerateAppSecretProof(string accessToken)
{
string result;
using (HMACSHA256 hMACSHA = new HMACSHA256(Encoding.get_ASCII().GetBytes(base.get_Options().AppSecret)))
{
byte[] array = hMACSHA.ComputeHash(Encoding.get_ASCII().GetBytes(accessToken));
StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i < array.Length; i++)
{
stringBuilder.Append(array[i].ToString("x2", CultureInfo.get_InvariantCulture()));
}
result = stringBuilder.ToString();
}
return result;
}
protected override string FormatScope()
{
return string.Join(",", base.get_Options().get_Scope());
}
}
}
のコードですが、コード自体よりも優れについて説明していない
FacebookHandler
を使用しています。エラーは、この作品からスローされますが、ミドルウェアからのコード:要するに var response = Backchannel.GetAsync(endpoint).Result; if (!response.IsSuccessStatusCode) { throw new HttpRequestException($"Failed to retrieve Facebook user information ({response.StatusCode}) Please check if the authentication information is correct and the corresponding Facebook Graph API is enabled."); }
、開発エラーが発生した場合は、一般的なエラーメッセージをスローします。実際のエラーが分かっていることを知るためには、Fiddlerなどのツールを使ってFacebookからの応答をキャプチャできます。私の場合、以下のようになります。
{"error":{"message": "構文エラー\ "文字\ 5:email; first_name; last_name"、 "type": "OAuthException"、 "code":2500、 "fbtrace_id": "xxxxxxxx"}}の代わりに、
- 1. libpngの役割は何ですか?
- 2. AVCaptureDeviceType.builtInDualCameraの役割は何ですか
- 3. `return`ステートメントの役割は何ですか?
- 4. QTreeWidgetItemの役割とは何ですか?
- 5. $ state.go( '。')の役割は何ですか?
- 6. のPostgres:役割を作成し、psqlでログイン-U役割
- 7. ログイン - 別のユーザーの役割
- 8. doctrineのObjectRepositoryとは何ですか?彼の役割は何ですか
- 9. Androidアプリケーションでは、 "R.java"の役割は何ですか?
- 10. "描画コンテキスト"とは何ですか? getcontext()メソッドの役割は何ですか?
- 11. Polymerの設定でNode.jsの役割は何ですか?
- 12. iOS版のReact NativeでRCTSRWebSocketの役割は何ですか?
- 13. Cプロジェクトでの.sファイルの役割は何ですか?
- 14. ブートストラップでのミックスインの役割は何ですか?
- 15. MVCでのアクティビティクラスの役割は何ですか?
- 16. CodeModelでClassOutline/JClass/CClassの役割は何ですか?
- 17. elasticsearch-osemで@Indexableの役割は何ですか?
- 18. ここでob_start()の役割は何ですか
- 19. Androidプロジェクトで.gradle。gradaフォルダの役割は何ですか?
- 20. Peoplesoft Process Schedulerの役割またはPSPRCSQUEとは何ですか?
- 21. カピストラーノの「役割」は正確には何ですか?
- 22. F#の計算式のwhileループの役割は何ですか?
- 23. 標準のウェブサイトのユーザー役割の名前は何ですか?
- 24. AWSアカウントで「仮定された役割」とは何ですか?
- 25. パラメータの前にアスタリスクの役割は何ですか?
- 26. データベースの分類の役割は何ですか?
- 27. .xibファイル内のプレースホルダの役割は何ですか?
- 28. コアアニメーションのキーパスの役割は何ですか?
- 29. 機械学習ソフトウェアの確率の役割は何ですか?
- 30. Goの "interface {}"構文の役割は何ですか?
あなたのお返事ありがとうございました これは私が探している答えではありません... – Issac