如何使用Xamarin.Auth获取访问令牌?

时间:2015-07-23 07:29:01

标签: c# authentication xamarin oauth-2.0 xamarin.auth

https://components.xamarin.com/gettingstarted/xamarin.auth

因此,该网站显示了如何对用户进行身份验证以及如何发出请求,但它跳过了将访问令牌从URL中取出的步骤。这可能非常简单,但这是我第一次使用API​​。如果有人可以查看该网站并确切了解我应该如何 A。)找到包含访问令牌的网址(我知道身份验证链接会在浏览器中将您重定向到它,但在Xamarin中.Auth,在验证之后,你直接回到应用程序而不是重定向网址。 B。)从网址中提取访问令牌。感谢。

1 个答案:

答案 0 :(得分:2)

取消选中"禁用隐式OAuth"在Instagram网站上的客户端安全设置中。

var auth = new OAuth2Authenticator (
               clientId: "CLIENT_ID",
               scope: "basic",
               authorizeUrl: new Uri ("https://api.instagram.com/oauth/authorize/"),
               redirectUrl: new Uri ("REDIRECT_URL"));

auth.AllowCancel = allowCancel;

// If authorization succeeds or is canceled, .Completed will be fired.
auth.Completed += (s, ee) => {
    var token = ee.Account.Properties ["access_token"];
};

var intent = auth.GetUI (this);
StartActivity (intent);

对于其他服务,您只需使用OAuth2Request来执行受保护的请求。

相关问题