【发布时间】:2017-03-09 03:23:20
【问题描述】:
我正在 android 上构建一个 REST 客户端来与 Bitbucket API 进行通信。 我遇到了 OAUTH2.0 的问题。
- 从Bitbucket提供的docs,你必须创建一个 "consumer" 以获取 ClientID(Key) 和 Secret 以用于 你的安卓应用
- 在消费者创建表单中,有“回调 URL”(我理解为 Bitbucket 将 在用户完成授予应用程序的权限后将其带到 (即登录)
- 在我的 android 应用程序中,我希望 android 设备在用户授予权限后返回我的应用程序(例如您如何使用 google 帐户登录网站,在 google 的权限页面上填写您的凭据后,您是被带回到原来的页面)
tutorial I was following 实现了这一点
- 在 manifest.xml 中进行登录的活动中添加此项
<intent-filter> <action android:name="android.intent.action.VIEW" /> <category android:name="android.intent.category.DEFAULT" /> <category android:name="android.intent.category.BROWSABLE" /> <data android:host="redirecturi" android:scheme="your" /> </intent-filter>
-
将此发送到 Bitbucket
private final String redirectUri = "your://redirecturi"; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_login); Button loginButton = (Button) findViewById(R.id.loginbutton); loginButton.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { Intent intent = new Intent( Intent.ACTION_VIEW, //Uri.parse("" + "/login" + "?client_id=" + clientId + "&redirect_uri=" + redirectUri)); Uri.parse("https://bitbucket.org/site/oauth2/authorize" + "?client_id=" + clientId + "&redirect_uri=" + redirectUri)); startActivity(intent); } }); }
我的问题是: - 如何在 Bitbucket 消费者对象和我的应用程序的请求中配置重定向 URI 或回调 URL,以确保 android 设备返回到我的应用程序,以便我的应用程序可以捕获来自 Bitbucket 的响应(并且此响应应该具有我的 access_token需要)。
【问题讨论】:
标签: android rest oauth-2.0 bitbucket-api