Browse Source

fix:fix initWithPlainTextAccessKey in android but we do not suggest use it

罗章 6 years ago
parent
commit
781d69f354
3 changed files with 5 additions and 23 deletions
  1. 2
    2
      README-CN.md
  2. 1
    1
      README.md
  3. 2
    20
      android/src/main/java/com/reactlibrary/AliyunAuthManager.java

+ 2
- 2
README-CN.md View File

191
 AliyunOSS.enableDevMode()
191
 AliyunOSS.enableDevMode()
192
 ```
192
 ```
193
 
193
 
194
-### initWithPlainTextAccessKey
194
+### initWithPlainTextAccessKey(不建议)
195
 
195
 
196
-该接口需要通过明文授权acckeyId和accekeySecret,使用可查看
196
+该接口需要通过明文授权acckeyId和accekeySecret,开发者这可以使用,但是我们不建议
197
 
197
 
198
 ```javascript
198
 ```javascript
199
 const endPoint = "XXX"
199
 const endPoint = "XXX"

+ 1
- 1
README.md View File

197
 
197
 
198
 ### initWithPlainTextAccessKey
198
 ### initWithPlainTextAccessKey
199
 
199
 
200
-init auth client with accessKeyId and accessKeySecret,please refer to the code.
200
+init auth client with accessKeyId and accessKeySecret,please refer to the code.you can use ,but we do not suggest use it。
201
 
201
 
202
 ```javascript
202
 ```javascript
203
 const endPoint = "XXX"
203
 const endPoint = "XXX"

+ 2
- 20
android/src/main/java/com/reactlibrary/AliyunAuthManager.java View File

10
 import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
10
 import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
11
 import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
11
 import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
12
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationCredentialProvider;
12
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationCredentialProvider;
13
+import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
13
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationToken;
14
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationToken;
14
 import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider;
15
 import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider;
15
 import com.alibaba.sdk.android.oss.common.utils.IOUtils;
16
 import com.alibaba.sdk.android.oss.common.utils.IOUtils;
83
                                            String accessKeySecret,
84
                                            String accessKeySecret,
84
                                            String endPoint,
85
                                            String endPoint,
85
                                            ReadableMap configuration) {
86
                                            ReadableMap configuration) {
86
-        OSSCredentialProvider credentialProvider = new OSSFederationCredentialProvider() {
87
-            @Override
88
-            public OSSFederationToken getFederationToken() {
89
-                try {
90
-                    URL stsUrl = new URL("http://yourip:port");
91
-                    HttpURLConnection conn = (HttpURLConnection) stsUrl.openConnection();
92
-                    InputStream input = conn.getInputStream();
93
-                    String jsonText = IOUtils.readStreamAsString(input, OSSConstants.DEFAULT_CHARSET_NAME);
94
-                    JSONObject jsonObjs = new JSONObject(jsonText);
95
-                    String ak = jsonObjs.getString("AccessKeyId");
96
-                    String sk = jsonObjs.getString("AccessKeySecret");
97
-                    String token = jsonObjs.getString("SecurityToken");
98
-                    String expiration = jsonObjs.getString("Expiration");
99
-                    return new OSSFederationToken(ak, sk, token, expiration);
100
-                } catch (Exception e) {
101
-                    e.printStackTrace();
102
-                }
103
-                return null;
104
-            }
105
-        };
106
 
87
 
88
+        OSSCredentialProvider credentialProvider = new OSSPlainTextAKSKCredentialProvider(accessKeyId,accessKeySecret);
107
         // init conf
89
         // init conf
108
         ClientConfiguration conf = ConfigUtils.initAuthConfig(configuration);
90
         ClientConfiguration conf = ConfigUtils.initAuthConfig(configuration);
109
 
91