Tran Triet Tran Triet - 1 year ago 95
reST (reStructuredText) Question

Redirect_URI for Android REST client

I am building a REST client on android to communicate with the Bitbucket API.
I am having problem with OAUTH2.0.

  • From the docs provided by Bitbucket, you have to create a
    "consumer" in order to obtain the ClientID(Key) and Secret to use for
    your android app

  • And in the consumer creation form, there's the "Callback URL" (which I understand as the webpage or location that Bitbucket will
    take user to after they have finished granted permission for the app
    (i.e. logging in)

  • In my android app, I want the android device to go back to my app after user has granted permission (like how you login to a website with google account, after filling in your credentials on the permission page of google, you are taken back to the original page you were on)

The tutorial I was following implements this by

  • Adding this in the activity in which the login takes place in manifest.xml

<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
android:scheme="your" />

  • Send this to Bitbucket

    private final String redirectUri = "your://redirecturi";

    protected void onCreate(Bundle savedInstanceState) {
    Button loginButton = (Button) findViewById(;
    loginButton.setOnClickListener(new View.OnClickListener() {
    public void onClick(View v) {
    Intent intent = new Intent(
    //Uri.parse("" + "/login" + "?client_id=" + clientId + "&redirect_uri=" + redirectUri));
    Uri.parse("" + "?client_id=" + clientId + "&redirect_uri=" + redirectUri));

My question is:
- How do I config the redirect URI or callback URL on Bitbucket consumer object and in my app's request to make sure the android device goes back to my app and so my app can catch responses from Bitbucket (and this response should have the access_token which I'll need).

Answer Source

An easy way to manage this is using a WebView rather than opeing your OAuth link through an intent. You can actually check the url whenever you are redirected in a WebView. To do so you have to override

public boolean shouldOverrideUrlLoading(WebView view, String url)

whenever you are redirected to another link ( or your callback uri in this case ) you can check or compare the url obtained and proceed accordingly.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download