我一直在使用 Schourode 的 Canoncialize 包来确保所有 url 都是小写的。我觉得它真的很方便,并想继续使用它。
https://github.com/schourode/canonicalize
但是我在使用 OAuthWebSecurity 时遇到了麻烦。AuthorizationResult 失败。在 route_config.cs 中删除对 Canonicalize 的调用使其再次工作。
我原本以为它是将请求令牌重写为小写,但正如 Chandu 指出的那样,我错了。现在我认为它可能与编码有关。但我不确定它究竟为什么会发生或如何解决它。:(
成功回调地址
http://localhost:54829/Account/ExternalLoginCallback?__provider__=google
& __sid__=fcb698f12ed04960927d4ac90e56e61e
& dnoa.userSuppliedIdentifier=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid
& openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0
& openid.mode=id_res
& openid.op_endpoint=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fud
& openid.response_nonce=2013-09-14T14%3A27%3A18Z6FEiPEQHHaoPbA
& openid.return_to=http%3A%2F%2Flocalhost%3A54829%2FAccount%2FExternalLoginCallback%3F__provider__%3Dgoogle%26__sid__%3Dfcb698f12ed04960927d4ac90e56e61e%26dnoa.userSuppliedIdentifier%3Dhttps%253A%252F%252Fwww.google.com%252Faccounts%252Fo8%252Fid
& openid.assoc_handle=1.AMlYA9UwBb4zH8OdmM32r_inWmnlZxOI5YYiDIyvZyYzWHSDOhrSr4BXyqr_o5hN
& openid.signed=op_endpoint%2Cclaimed_id%2Cidentity%2Creturn_to%2Cresponse_nonce%2Cassoc_handle%2Cns.ext1%2Cext1.mode%2Cext1.type.alias1%2Cext1.value.alias1
& openid.sig=hnrnpAd6y%2FnNsZ%2F%2F%2FUxwF5y3fdQ%3D
& openid.identity=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawnOx9rmVJrEUZJ_Kw7O513sw1IE4I7kBhE
& openid.claimed_id=https%3A%2F%2Fwww.google.com%2Faccounts%2Fo8%2Fid%3Fid%3DAItOawnOx9rmVJrEUZJ_Kw7O513sw1IE4I7kBhE
& openid.ns.ext1=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0
& openid.ext1.mode=fetch_response
& openid.ext1.type.alias1=http%3A%2F%2Faxschema.org%2Fcontact%2Femail
& openid.ext1.value.alias1=myemail%40gmail.com
回调地址失败
http://localhost:54829/account/externallogincallback?__provider__=google
& __sid__=49c61b3f66404ec0bedfa36764d462cc
& dnoa.userSuppliedIdentifier=https://www.google.com/accounts/o8/id
& openid.ns=http://specs.openid.net/auth/2.0
& openid.mode=id_res
& openid.op_endpoint=https://www.google.com/accounts/o8/ud
& openid.response_nonce=2013-09-14T14:25:49ZRLQRLeenDyhw3A
& openid.return_to=http://localhost:54829/Account/ExternalLoginCallback?__provider__=google
& __sid__=49c61b3f66404ec0bedfa36764d462cc
& dnoa.userSuppliedIdentifier=https%253A%252F%252Fwww.google.com%252Faccounts%252Fo8%252Fid
& openid.assoc_handle=1.AMlYA9WrOftO7I7kuyIEwBrDNP-7SXGCRijUDbHG_7yNd_SuasIglPfyLWegbAD6
& openid.signed=op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.alias1,ext1.value.alias1
& openid.sig=SMD+cRIfP3E3Y9lZ29tBFBmg2uE=
& openid.identity=https://www.google.com/accounts/o8/id?id=AItOawnOx9rmVJrEUZJ_Kw7O513sw1IE4I7kBhE
& openid.claimed_id=https://www.google.com/accounts/o8/id?id=AItOawnOx9rmVJrEUZJ_Kw7O513sw1IE4I7kBhE
& openid.ns.ext1=http://openid.net/srv/ax/1.0
& openid.ext1.mode=fetch_response
& openid.ext1.type.alias1=http://axschema.org/contact/email
& openid.ext1.value.alias1=myemail@gmail.com
这是造成或破坏它的调用:
public class RouteConfig
{
public static void RegisterRoutes(RouteCollection routes)
{
// removing this causes oAuth to work ok
routes.Canonicalize().NoWww().Lowercase().NoTrailingSlash();
routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Default", id = UrlParameter.Optional }
);
}
}