aliyun-oss-react-native

AuthManager.js 2.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. import React, { Component } from 'react';
  2. import {
  3. Platform,
  4. StyleSheet,
  5. Text,
  6. View,
  7. Alert,
  8. Button,
  9. ScrollView,
  10. Image
  11. } from 'react-native';
  12. const configuration = {
  13. maxRetryCount: 3,
  14. timeoutIntervalForRequest: 30,
  15. timeoutIntervalForResource: 24 * 60 * 60
  16. };
  17. const config = {
  18. AccessKey: 'XXX',
  19. SecretKey: 'XXX',
  20. };
  21. const STSConfig = {
  22. AccessKeyId:'XXX',
  23. SecretKeyId:'XXX',
  24. SecurityToken:'XXX'
  25. }
  26. const endPoint = 'oss-cn-zhangjiakou.aliyuncs.com';
  27. const companyserver = "http://XXX:PORT"
  28. const familyserver = "http://XXX:PORT"
  29. //导入样式
  30. import { styles } from '../CSS/global.js'
  31. export class AuthManager extends Component {
  32. render() {
  33. return (
  34. <View style={styles.item}>
  35. <Text style={styles.description}>Client初始化</Text>
  36. <View style={styles.detailitem}>
  37. <View style={styles.button}>
  38. <Button
  39. onPress={this.handClick.bind(this,"AKSK")}
  40. title="AKSK明文"
  41. color="#841584"
  42. />
  43. </View>
  44. <View style={styles.button}>
  45. <Button style={styles.button}
  46. onPress={this.handClick.bind(this,"Singer")}
  47. title="自签"
  48. color="#841584"
  49. />
  50. </View>
  51. <View style={styles.button}>
  52. <Button style={styles.button}
  53. onPress={this.handClick.bind(this,"STS")}
  54. title="STS"
  55. color="#841584"
  56. />
  57. </View>
  58. <View style={styles.button}>
  59. <Button style={styles.button}
  60. onPress={this.handClick.bind(this,"ServerSTS")}
  61. title="Server STS"
  62. color="#841584"
  63. />
  64. </View>
  65. </View>
  66. </View>
  67. )
  68. }
  69. handClick(e) {
  70. switch(e) {
  71. case 'AKSK' : {
  72. Alert.alert(Platform.OS);
  73. if (Platform.OS == 'ios') {
  74. AliyunOSS.initWithPlainTextAccessKey(config.AccessKey,config.SecretKey,endPoint,configuration);
  75. Alert.alert("initAKSK success!")
  76. } else {
  77. Alert.alert('android do not support AK SK ,please use initWithSTS')
  78. }
  79. } break;
  80. case 'Singer' : {
  81. Alert.alert('initAKSK')
  82. } break;
  83. case "STS": {
  84. AliyunOSS.initWithSecurityToken(STSConfig.SecurityToken,STSConfig.AccessKeyId,STSConfig.SecretKeyId,endPoint,configuration)
  85. Alert.alert('STS success!')
  86. } break;
  87. case "ServerSTS" : {
  88. AliyunOSS.initWithServerSTS(familyserver,endPoint, configuration)
  89. Alert.alert('initServerSTS Success!')
  90. } break;
  91. default: break;
  92. }
  93. }
  94. }