I have an application uses Linkedin api and authentication process is achieved by scribe library. My test device has official linkedin application already and it is signed in. My authentication codes ask email adress and password at every run time. But if official linkedin app installed and signed in,I want auth from that application. So do you know a way to authentication which doesnt need email and pasword ?
My auth codes:
public class LinkedInOauth extends Activity{
private WebView mWebView;
private Token mRequestToken;
private OAuthService mService;
private ProgressDialog pd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
setContentView(R.layout.linkedin_oauth);
pd = new ProgressDialog(this);
pd.setMessage("Bekle");
pd.setCanceledOnTouchOutside(false);
mService = new ServiceBuilder()
.provider(LinkedInApi.class)
.apiKey(Util.CONSUMER_KEY)
.apiSecret(Util.CONSUMER_SECRET)
.callback(Util.OAUTH_CALLBACK)
.scope("r_basicprofile")
.scope("rw_nus")
.build();
mWebView=(WebView)findViewById(R.id.linkedin_webview);
pd.show();
(new LinkedInAuthTask()).execute();
}
private class LinkedInAuthTask extends AsyncTask<Void, Void, String> {
@Override
protected String doInBackground(Void... arg0) {
String authURL = "http://api.linkedin.com/";
try {
mRequestToken = mService.getRequestToken();
authURL = mService.getAuthorizationUrl(mRequestToken);
}
catch ( OAuthException e ) {
e.printStackTrace();
return null;
}
return authURL;
}
@Override
protected void onPostExecute(String authURL) {
mWebView.setWebViewClient(new WebViewClient() {
@Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
super.shouldOverrideUrlLoading(view, url);
if( url.startsWith("oauth") ) {
mWebView.setVisibility(WebView.GONE);
final String url1 = url;
Thread t1 = new Thread() {
public void run() {
Uri uri = Uri.parse(url1);
String verifier = uri.getQueryParameter("oauth_verifier");
Verifier v = new Verifier(verifier);
Token accessToken = mService.getAccessToken(mRequestToken, v);
Intent intent = new Intent();
intent.putExtra("access_token", accessToken.getToken());
intent.putExtra("access_secret", accessToken.getSecret());
setResult(RESULT_OK, intent);
finish();
}
};
t1.start();
}
return false;
}
@Override
public void onPageFinished(WebView view, String url) {
super.onPageFinished(view, url);
pd.dismiss();
}
});
mWebView.loadUrl(authURL);
}
}
}
0 comments:
Post a Comment