浏览代码

Make the OAuth authorization available or not depending upon a variable in oauth.xml

David A. Velasco 12 年之前
父节点
当前提交
2e5b40e357

+ 5 - 0
res/values/oauth2_configuration.xml

@@ -1,5 +1,10 @@
 <?xml version="1.0" encoding="utf-8"?>
 <resources>
+    <!-- Flag to configure OAuth availability in the app.
+    	 3 valid values now: on, off, optional	
+     -->
+    <string name="oauth2_mode">off</string>
+    
     <!-- constants that must be respected by the authorization server; if changed, the app must be rebuild -->
     <string name="oauth2_redirect_scheme">owncloud</string>
     <string name="oauth2_redirect_uri">owncloud://callback</string>

+ 9 - 2
src/com/owncloud/android/authentication/AuthenticatorActivity.java

@@ -87,6 +87,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
     private static final String KEY_IS_SSL_CONN = "IS_SSL_CONN";
     private static final String KEY_OAUTH2_STATUS_TEXT = "OAUTH2_STATUS_TEXT";
     private static final String KEY_OAUTH2_STATUS_ICON = "OAUTH2_STATUS_ICON";
+    
+    private static final String OAUTH_MODE_ON = "on";
+    private static final String OAUTH_MODE_OFF = "off";
+    private static final String OAUTH_MODE_OPTIONAL = "optional";
 
     private static final int DIALOG_LOGIN_PROGRESS = 0;
     private static final int DIALOG_SSL_VALIDATOR = 1;
@@ -154,7 +158,6 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
         mOkButton = findViewById(R.id.buttonOK);
         mAuthStatusLayout = (TextView) findViewById(R.id.auth_status_text); 
         
-
         /// complete label for 'register account' button
         Button b = (Button) findViewById(R.id.account_register);
         if (b != null) {
@@ -179,7 +182,7 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             
             /// retrieve extras from intent
             String tokenType = getIntent().getExtras().getString(AccountAuthenticator.KEY_AUTH_TOKEN_TYPE);
-            boolean oAuthRequired = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(tokenType);
+            boolean oAuthRequired = AccountAuthenticator.AUTH_TOKEN_TYPE_ACCESS_TOKEN.equals(tokenType) || OAUTH_MODE_ON.equals(getString(R.string.oauth2_mode));
             
             mAccount = getIntent().getExtras().getParcelable(EXTRA_ACCOUNT);
             if (mAccount != null) {
@@ -201,6 +204,10 @@ public class AuthenticatorActivity extends AccountAuthenticatorActivity
             loadSavedInstanceState(savedInstanceState);
         }
         
+        if (!OAUTH_MODE_OPTIONAL.equals(getString(R.string.oauth2_mode))) {
+            mOAuth2Check.setVisibility(View.GONE);
+        }
+        
         if (mAction == ACTION_UPDATE_TOKEN) {
             /// lock things that should not change
             mHostUrlInput.setEnabled(false);