Merge lp:~karni/ubuntu-sso-android-library/use-the-consumer into lp:ubuntu-sso-android-library

Proposed by Michał Karnicki
Status: Merged
Merged at revision: 41
Proposed branch: lp:~karni/ubuntu-sso-android-library/use-the-consumer
Merge into: lp:ubuntu-sso-android-library
Diff against target: 172 lines (+27/-40)
2 files modified
src/com/ubuntu/android/sso/activity/SSOLoginActivity.java (+13/-33)
src/com/ubuntu/android/sso/authenticator/AuthenticatorActivity.java (+14/-7)
To merge this branch: bzr merge lp:~karni/ubuntu-sso-android-library/use-the-consumer
Reviewer Review Type Date Requested Status
Chad Miller (community) Approve
Review via email: mp+79261@code.launchpad.net

Description of the change

Use the real consumer, not ubuntuone/hammertime. SSOLoginActivity saves this into one new preference field, oauth_data (consumer_key:consumer_secret:access_token:access_secret).

To post a comment you must log in.
41. By Michał Karnicki

Return the token post registration as well.

Revision history for this message
Chad Miller (cmiller) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/com/ubuntu/android/sso/activity/SSOLoginActivity.java'
2--- src/com/ubuntu/android/sso/activity/SSOLoginActivity.java 2011-10-11 13:44:52 +0000
3+++ src/com/ubuntu/android/sso/activity/SSOLoginActivity.java 2011-10-13 11:29:32 +0000
4@@ -22,8 +22,6 @@
5
6 package com.ubuntu.android.sso.activity;
7
8-import java.util.StringTokenizer;
9-
10 import android.accounts.Account;
11 import android.accounts.AccountManager;
12 import android.app.Activity;
13@@ -46,25 +44,16 @@
14
15 private static final int REQUEST_AUTHENTICATE = 1;
16
17- public static final int RESULT_AUTHENTICATE_OK = RESULT_FIRST_USER;
18- public static final int RESULT_AUTHENTICATE_ERROR = RESULT_FIRST_USER + 1;
19-
20 public static final String KEY_INVALIDATE_TOKEN = "invalidate";
21
22 private GoogleAnalyticsTracker mTracker;
23
24- private SharedPreferences mSharedPreferences;
25- private Editor mEditor;
26-
27 @Override
28 protected void onCreate(Bundle savedInstanceState) {
29 super.onCreate(savedInstanceState);
30
31 setContentView(R.layout.sso_entry);
32
33- mSharedPreferences = PreferenceManager.getDefaultSharedPreferences(this);
34- mEditor = mSharedPreferences.edit();
35-
36 mTracker = GoogleAnalyticsTracker.getInstance();
37 mTracker.start(Analytics.ACCOUNT, this);
38 mTracker.trackPageView(TAG);
39@@ -83,7 +72,7 @@
40 if (resultCode == RESULT_OK) {
41 gotAccount(false);
42 } else {
43- setResult(RESULT_AUTHENTICATE_ERROR, data);
44+ setResult(RESULT_CANCELED, data);
45 overridePendingTransition(
46 android.R.anim.fade_in, android.R.anim.fade_out);
47 finish();
48@@ -138,7 +127,9 @@
49 }
50 });
51 } catch (Exception e) {
52- setResult(RESULT_AUTHENTICATE_ERROR);
53+ final Intent data = new Intent();
54+ data.putExtra("error", e.getMessage());
55+ setResult(RESULT_CANCELED, data);
56 e.printStackTrace();
57 finish();
58 }
59@@ -148,13 +139,7 @@
60
61 private void onGetTokenResult(String token) {
62 setSerializedOAuthToken(token);
63- final StringTokenizer tokens = new StringTokenizer(token, ":");
64- tokens.nextToken();
65- tokens.nextToken();
66- final String oauthToken = tokens.nextToken();
67- final String oauthSecret = tokens.nextToken();
68- setAccessToken(oauthToken, oauthSecret);
69- setResult(RESULT_AUTHENTICATE_OK);
70+ setResult(RESULT_OK);
71 finish();
72 }
73
74@@ -162,9 +147,9 @@
75 public boolean onKeyDown(int keyCode, KeyEvent event) {
76 // Was the Back button pressed?
77 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
78- Intent intent = new Intent();
79- intent.putExtra(AccountManager.KEY_AUTH_FAILED_MESSAGE, "cancelled");
80- setResult(RESULT_AUTHENTICATE_ERROR, intent);
81+ final Intent data = new Intent();
82+ data.putExtra("error", "Cancelled.");
83+ setResult(RESULT_CANCELED, data);
84 return true;
85 }
86 return super.onKeyDown(keyCode, event);
87@@ -180,20 +165,15 @@
88 }
89
90 public void addAccount() {
91- final Intent intent = new Intent("com.ubuntu.android.sso.ACTION_AUTHENTICATE");
92+ final Intent intent = new Intent(this, AuthenticatorActivity.class);
93 startActivityForResult(intent, REQUEST_AUTHENTICATE);
94 }
95
96- private void setAccessToken(
97- final String token, final String secret) {
98- mEditor.putString(Constants.KEY_ACCESS_TOKEN, token);
99- mEditor.putString(Constants.KEY_ACCESS_SECRET, secret);
100- mEditor.commit();
101- }
102-
103 private void setSerializedOAuthToken(final String serializedToken) {
104- mEditor.putString(Constants.KEY_SERIALIZED_TOKEN, serializedToken);
105- mEditor.commit();
106+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
107+ final Editor editor = prefs.edit();
108+ editor.putString(Constants.KEY_SERIALIZED_TOKEN, serializedToken);
109+ editor.commit();
110 }
111
112 public static void showFrom(Context context, String appTitle) {
113
114=== modified file 'src/com/ubuntu/android/sso/authenticator/AuthenticatorActivity.java'
115--- src/com/ubuntu/android/sso/authenticator/AuthenticatorActivity.java 2011-10-11 13:44:52 +0000
116+++ src/com/ubuntu/android/sso/authenticator/AuthenticatorActivity.java 2011-10-13 11:29:32 +0000
117@@ -279,9 +279,9 @@
118 public boolean onKeyDown(int keyCode, KeyEvent event) {
119 if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 0) {
120 Log.w(TAG, "Ubuntu SSO wizard was canceled.");
121- final Intent intent = new Intent();
122- intent.putExtra(AccountManager.KEY_AUTH_FAILED_MESSAGE, "cancelled");
123- setResult(RESULT_CANCELED, intent);
124+ final Intent data = new Intent();
125+ data.putExtra("error", "Canceled.");
126+ setResult(RESULT_CANCELED, data);
127 }
128 return super.onKeyDown(keyCode, event);
129 }
130@@ -313,9 +313,9 @@
131 new DialogInterface.OnClickListener() {
132 public void onClick(DialogInterface dialog, int which) {
133 dialog.dismiss();
134- final Intent intent = new Intent();
135- intent.putExtra(AccountManager.KEY_AUTH_FAILED_MESSAGE, "failed to adjust time");
136- setResult(RESULT_CANCELED);
137+ final Intent data = new Intent();
138+ data.putExtra("error", "Failed to verify device time.");
139+ setResult(RESULT_CANCELED, data);
140 finish();
141 }
142 });
143@@ -920,6 +920,10 @@
144 result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
145 result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
146 setAccountAuthenticatorResult(result);
147+
148+ final Intent data = new Intent();
149+ data.putExtra("oauth_data", authToken);
150+ setResult(RESULT_OK, data);
151 Log.i(TAG, "Correctly set the auth token.");
152 } catch (AuthenticationException e) {
153 Log.e(TAG, "Failed to authenticate. " + e.getMessage());
154@@ -979,7 +983,6 @@
155 backButton.setVisibility(View.INVISIBLE);
156 nextButton.setVisibility(View.VISIBLE);
157 */
158- setResult(RESULT_OK);
159 finish();
160 overridePendingTransition(
161 android.R.anim.fade_in, android.R.anim.fade_out);
162@@ -1228,6 +1231,10 @@
163 result.putString(AccountManager.KEY_ACCOUNT_TYPE, Constants.ACCOUNT_TYPE);
164 result.putString(AccountManager.KEY_AUTHTOKEN, authToken);
165 setAccountAuthenticatorResult(result);
166+
167+ final Intent data = new Intent();
168+ data.putExtra("oauth_data", authToken);
169+ setResult(RESULT_OK, data);
170 } catch (EmailTokenException e) {
171 Log.e(TAG, "Failed to validate with token: " + e.getMessage());
172 exception = e;

Subscribers

People subscribed via source and target branches