I am building a REST client on android to communicate with the Bitbucket API. I am having problem with OAUTH2.0.
The tutorial I was following implements this by
<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>
Send this to 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);
}
});
}
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).
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.