WebAuthenticationBroker似乎无法处理到我的ms-app://
的导航。就像下面看到的那样,抛出这个丑陋的错误。
步骤
AuthenticateAsync()
,包括在运行时获得的回调uri:WebAuthenticationBroker.GetCurrentApplicationCallbackUri()
"The specified protocol is unknown. (Exception from HRESULT: 0x800C000D)"
WebAuthenticationBroker.AuthenticateAsync()
的回调被接收(根据Fiddler4 & Event ),但是它抛出上述异常,就好像它不知道如何解释ms-app://
协议一样。
所有的例子都暗示我的代码应该能工作,但是我认为有一些不太明显的问题引起了问题。
代码
private static string authorizeString =
"https://api.imgur.com/oauth2/authorize?client_id=---------&response_type=token";
private Uri startUri = new Uri(authorizeString);
public async void RequestToken() {
try {
var war = await WebAuthenticationBroker.AuthenticateAsync(
WebAuthenticationOptions.UseTitle
, startUri);
// Imgur knows my redirect URI, so I am not passing it through here
if (war.ResponseStatus == WebAuthenticationStatus.Success) {
var token = war.ResponseData;
}
} catch (Exception e) { throw e; }
}
事件查看器日志摘录(按时间顺序)
有关我是如何获得此功能的信息,请阅读以下MSDN:Web身份验证问题(Windows)。不幸的是,这是查询authhost.exe导航错误时的唯一搜索结果。
AuthHost redirected to URL: <ms-app://s-1-15-2-504558873-2277781482-774653033-676865894-877042302-1411577334-1137525427/#access_token=------&expires_in=3600&token_type=bearer&refresh_token=------&account_username=------> from URL: <https://api.imgur.com/oauth2/authorize?client_id=------&response_type=token> with HttpStatusCode: 302.
AuthHost encountered a navigation error at URL: <https://api.imgur.com/oauth2/authorize?client_id=------&response_type=token> with StatusCode: 0x800C000D.
AuthHost encountered Meta Tag: mswebdialog-title with content: <Can't connect to the service>.
谢谢你的阅读,斯塔克。别让我失望了!
发布于 2013-02-08 13:43:50
@ma_il帮助我理解了代理是如何评估重定向回调的,它使我回到了原点,在那里我意识到WebAuthenticationOptions.UseTitle是正确的用法。不是。它需要使用WebAuthenticationOptions.None
,并且可以立即工作。
作为未来寻找答案者的一个例子,这是我的代码。
private const string clientId = "---------";
private static Uri endUri = WebAuthenticationBroker.GetCurrentApplicationCallbackUri();
private static string authorizeString = "https://api.imgur.com/oauth2/authorize?"
+ "client_id="
+ clientId
+ "&response_type=token"
+ "&state=somestateyouwant"
+ "&redirect_uri="
+ endUri;
private Uri startUri = new Uri(authorizeString);
public async void RequestToken() {
try {
WebAuthenticationResult webAuthenticationResult =
await WebAuthenticationBroker.AuthenticateAsync(WebAuthenticationOptions.None
, startUri
, endUri);
if (webAuthenticationResult.ResponseStatus == WebAuthenticationStatus.Success) {
string token = webAuthenticationResult.ResponseData;
// now you have the token
}
} catch { throw; }
}
发布于 2013-02-07 10:44:52
Afaik,即使您假设远程服务知道它,也需要将end传递给AuthenticateAsync。
WebAuthenticationBroker的工作方式如下所示:您指定了一个“端点”URL,当它遇到以该URL开头的链接时,它将认为身份验证过程已经完成,甚至不再尝试导航到该URL。因此,如果您将"foo://bar“指定为回调URI,导航到"foo://bar”将完成身份验证,而"foo://barbaz“将完成身份验证,而不是"foo://baz”。
https://stackoverflow.com/questions/14742974
复制相似问题