Quellcode durchsuchen

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

罗章 vor 6 Jahren
Ursprung
Commit
781d69f354
3 geänderte Dateien mit 5 neuen und 23 gelöschten Zeilen
  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 Datei anzeigen

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

+ 1
- 1
README.md Datei anzeigen

@@ -197,7 +197,7 @@ AliyunOSS.enableDevMode()
197 197
 
198 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 202
 ```javascript
203 203
 const endPoint = "XXX"

+ 2
- 20
android/src/main/java/com/reactlibrary/AliyunAuthManager.java Datei anzeigen

@@ -10,6 +10,7 @@ import com.alibaba.sdk.android.oss.common.OSSConstants;
10 10
 import com.alibaba.sdk.android.oss.common.auth.OSSCredentialProvider;
11 11
 import com.alibaba.sdk.android.oss.common.auth.OSSCustomSignerCredentialProvider;
12 12
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationCredentialProvider;
13
+import com.alibaba.sdk.android.oss.common.auth.OSSPlainTextAKSKCredentialProvider;
13 14
 import com.alibaba.sdk.android.oss.common.auth.OSSFederationToken;
14 15
 import com.alibaba.sdk.android.oss.common.auth.OSSStsTokenCredentialProvider;
15 16
 import com.alibaba.sdk.android.oss.common.utils.IOUtils;
@@ -83,27 +84,8 @@ public class AliyunAuthManager {
83 84
                                            String accessKeySecret,
84 85
                                            String endPoint,
85 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 89
         // init conf
108 90
         ClientConfiguration conf = ConfigUtils.initAuthConfig(configuration);
109 91