aws-sdk 2.0.1 → 2.0.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (251) hide show
  1. package/.eslintrc +20 -0
  2. package/.gitignore +10 -0
  3. package/.travis.yml +20 -0
  4. package/.yardopts +20 -0
  5. package/.yardopts_guide +21 -0
  6. package/Gemfile +16 -0
  7. package/Gemfile.lock +34 -0
  8. package/README.md +5 -6
  9. package/Rakefile +14 -0
  10. package/UPGRADING.md +9 -4
  11. package/configuration.sample +5 -0
  12. package/dist/BUNDLE_LICENSE.txt +96 -0
  13. package/dist/aws-sdk.js +9594 -0
  14. package/dist/aws-sdk.min.js +21 -0
  15. package/dist-tools/.eslintrc +10 -0
  16. package/dist-tools/browser-builder.js +142 -0
  17. package/dist-tools/strategies/cache.js +68 -0
  18. package/dist-tools/strategies/default.js +165 -0
  19. package/dist-tools/test/browser-builder.mocha.spec.coffee +182 -0
  20. package/dist-tools/test/helpers.coffee +16 -0
  21. package/doc-src/guide/browser-building.md +93 -0
  22. package/doc-src/guide/browser-configuring-wif.md +287 -0
  23. package/doc-src/guide/browser-configuring.md +218 -0
  24. package/doc-src/guide/browser-examples.md +220 -0
  25. package/doc-src/guide/browser-intro.md +46 -0
  26. package/doc-src/guide/browser-making-requests.md +279 -0
  27. package/doc-src/guide/browser-services.md +75 -0
  28. package/doc-src/guide/index.md +41 -0
  29. package/doc-src/guide/node-configuring.md +272 -0
  30. package/doc-src/guide/node-examples.md +341 -0
  31. package/doc-src/guide/node-intro.md +32 -0
  32. package/doc-src/guide/node-making-requests.md +309 -0
  33. package/doc-src/guide/node-services.md +159 -0
  34. package/doc-src/templates/api-versions/model_documentor.rb +366 -0
  35. package/doc-src/templates/api-versions/plugin.rb +230 -0
  36. package/doc-src/templates/api-versions/templates/default/class/html/setup.rb +9 -0
  37. package/doc-src/templates/api-versions/templates/default/class/html/waiter_details_list.erb +7 -0
  38. package/doc-src/templates/api-versions/templates/default/class/html/waiter_summary.erb +7 -0
  39. package/doc-src/templates/api-versions/templates/default/docstring/html/experimental.erb +4 -0
  40. package/doc-src/templates/api-versions/templates/default/docstring/setup.rb +9 -0
  41. package/doc-src/templates/api-versions/templates/default/fulldoc/html/css/common.css +6 -0
  42. package/doc-src/templates/api-versions/templates/default/fulldoc/html/setup.rb +62 -0
  43. package/doc-src/templates/api-versions/templates/default/layout/html/services.erb +10 -0
  44. package/doc-src/templates/api-versions/templates/default/layout/html/setup.rb +28 -0
  45. package/doc-src/templates/api-versions/templates/default/module/html/box_info.erb +45 -0
  46. package/doc-src/templates/api-versions/templates/default/module/html/children.erb +8 -0
  47. package/doc-src/templates/api-versions/templates/default/tags/setup.rb +3 -0
  48. package/doc-src/templates/api-versions/templates/default/waiter_details/html/method_signature.erb +3 -0
  49. package/doc-src/templates/api-versions/templates/default/waiter_details/html/setup.rb +5 -0
  50. package/doc-src/templates/default/layout/html/footer.erb +31 -0
  51. package/doc-src/templates/default/layout/html/layout.erb +23 -0
  52. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/highlight.github.css +127 -0
  53. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/css/style.css +1192 -0
  54. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/img/logo.png +0 -0
  55. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/app.js +33 -0
  56. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/highlight.pack.js +27 -0
  57. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/AUTHORS +55 -0
  58. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/LICENSE +25 -0
  59. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/doctools.js +247 -0
  60. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/file.png +0 -0
  61. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/sphinx/searchtools.js +568 -0
  62. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/js/underscore.js +23 -0
  63. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search.erb +29 -0
  64. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/search_index.erb +1 -0
  65. package/doc-src/templates/flasky_sphinx_guide/fulldoc/html/setup.rb +75 -0
  66. package/doc-src/templates/flasky_sphinx_guide/layout/html/layout.erb +93 -0
  67. package/doc-src/templates/flasky_sphinx_guide/layout/html/setup.rb +9 -0
  68. package/doc-src/templates/flasky_sphinx_guide/layout/html/sidebar.erb +45 -0
  69. package/doc-src/templates/flasky_sphinx_guide/onefile/html/layout.erb +51 -0
  70. package/doc-src/templates/flasky_sphinx_guide/onefile/html/setup.rb +1 -0
  71. package/eslint-rules/no-require-in-service.js +10 -0
  72. package/features/autoscaling/autoscaling.feature +21 -0
  73. package/features/autoscaling/step_definitions/autoscaling.js +49 -0
  74. package/features/cloudformation/cloudformation.feature +22 -0
  75. package/features/cloudformation/step_definitions/cloudformation.js +26 -0
  76. package/features/cloudfront/cloudfront.feature +28 -0
  77. package/features/cloudfront/step_definitions/cloudfront-latest.js +54 -0
  78. package/features/cloudfront/step_definitions/cloudfront.js +21 -0
  79. package/features/cloudsearch/cloudsearch.feature +34 -0
  80. package/features/cloudsearch/step_definitions/cloudsearch.js +42 -0
  81. package/features/cloudtrail/cloudtrail.feature +17 -0
  82. package/features/cloudtrail/step_definitions/cloudtrail.js +14 -0
  83. package/features/cloudwatch/cloudwatch.feature +15 -0
  84. package/features/cloudwatch/step_definitions/cloudwatch.js +48 -0
  85. package/features/datapipeline/datapipeline.feature +23 -0
  86. package/features/datapipeline/step_definitions/datapipeline.js +79 -0
  87. package/features/directconnect/directconnect.feature +20 -0
  88. package/features/directconnect/step_definitions/directconnect.js +44 -0
  89. package/features/dynamodb/crc32.feature +18 -0
  90. package/features/dynamodb/step_definitions/dynamodb.js +154 -0
  91. package/features/dynamodb/tables.feature +50 -0
  92. package/features/ec2/ec2.feature +28 -0
  93. package/features/ec2/step_definitions/ec2.js +65 -0
  94. package/features/elasticache/elasticache.feature +20 -0
  95. package/features/elasticache/step_definitions/elasticache.js +34 -0
  96. package/features/elasticbeanstalk/elasticbeanstalk.feature +22 -0
  97. package/features/elasticbeanstalk/step_definitions/elasticbeanstalk.js +38 -0
  98. package/features/elastictranscoder/elastictranscoder.feature +24 -0
  99. package/features/elastictranscoder/step_definitions/elastictranscoder.js +56 -0
  100. package/features/elb/elb.feature +19 -0
  101. package/features/elb/step_definitions/elb.js +37 -0
  102. package/features/emr/emr.feature +16 -0
  103. package/features/emr/step_definitions/emr.js +45 -0
  104. package/features/extra/assertions.js +29 -0
  105. package/features/extra/dummy.feature +0 -0
  106. package/features/extra/fixtures/testfile.txt +1 -0
  107. package/features/extra/helpers.js +113 -0
  108. package/features/extra/hooks.js +107 -0
  109. package/features/extra/world.js +12 -0
  110. package/features/glacier/glacier.feature +47 -0
  111. package/features/glacier/step_definitions/glacier.js +112 -0
  112. package/features/iam/iam.feature +24 -0
  113. package/features/iam/step_definitions/iam.js +66 -0
  114. package/features/importexport/importexport.feature +53 -0
  115. package/features/importexport/step_definitions/importexport.js +42 -0
  116. package/features/kinesis/kinesis.feature +9 -0
  117. package/features/kinesis/step_definitions/kinesis.js +10 -0
  118. package/features/opsworks/opsworks.feature +26 -0
  119. package/features/opsworks/step_definitions/opsworks.js +42 -0
  120. package/features/rds/rds.feature +32 -0
  121. package/features/rds/step_definitions/rds.js +72 -0
  122. package/features/redshift/redshift.feature +20 -0
  123. package/features/redshift/step_definitions/redshift.js +33 -0
  124. package/features/route53/route53.feature +41 -0
  125. package/features/route53/step_definitions/route53.js +97 -0
  126. package/features/s3/buckets.feature +40 -0
  127. package/features/s3/objects.feature +122 -0
  128. package/features/s3/step_definitions/buckets.js +136 -0
  129. package/features/s3/step_definitions/hooks.js +39 -0
  130. package/features/s3/step_definitions/objects.js +204 -0
  131. package/features/s3/step_definitions/proxy.js +44 -0
  132. package/features/ses/ses.feature +20 -0
  133. package/features/ses/step_definitions/ses.js +22 -0
  134. package/features/simpledb/simpledb.feature +29 -0
  135. package/features/simpledb/step_definitions/simpledb.js +46 -0
  136. package/features/sns/sns.feature +15 -0
  137. package/features/sns/step_definitions/sns.js +33 -0
  138. package/features/sqs/messages.feature +21 -0
  139. package/features/sqs/queues.feature +18 -0
  140. package/features/sqs/step_definitions/messages.js +46 -0
  141. package/features/sqs/step_definitions/queues.js +33 -0
  142. package/features/sqs/step_definitions/sqs.js +7 -0
  143. package/features/storagegateway/step_definitions/storagegateway.js +16 -0
  144. package/features/storagegateway/storagegateway.feature +13 -0
  145. package/features/sts/step_definitions/sts.js +35 -0
  146. package/features/sts/sts.feature +29 -0
  147. package/features/support/step_definitions/support.js +35 -0
  148. package/features/support/support.feature +18 -0
  149. package/features/swf/step_definitions/swf.js +38 -0
  150. package/features/swf/swf.feature +15 -0
  151. package/index.js +2 -0
  152. package/lib/core.js +2 -2
  153. package/lib/credentials/shared_ini_file_credentials.js +0 -1
  154. package/lib/event_listeners.js +13 -1
  155. package/lib/http/node.js +19 -30
  156. package/lib/model/resource_waiter.js +0 -4
  157. package/lib/model/shape.js +2 -1
  158. package/lib/protocol/rest_xml.js +1 -1
  159. package/lib/region_config.js +31 -0
  160. package/lib/region_config.json +56 -0
  161. package/lib/request.js +37 -45
  162. package/lib/sequential_executor.js +17 -34
  163. package/lib/service.js +17 -44
  164. package/lib/services/cloudsearchdomain.js +69 -0
  165. package/lib/services/route53.js +0 -12
  166. package/lib/services/s3.js +3 -19
  167. package/lib/signers/v4.js +2 -1
  168. package/lib/util.js +28 -3
  169. package/package.json +3 -3
  170. package/scripts/console +11 -3
  171. package/scripts/coverage +126 -0
  172. package/tasks/apis.rake +122 -0
  173. package/tasks/browser.rake +89 -0
  174. package/tasks/docs.rake +36 -0
  175. package/tasks/lib/cucumber_generator.rb +40 -0
  176. package/tasks/util.rake +33 -0
  177. package/test/browser/js/jasmine-1.3.1.js +2600 -0
  178. package/test/browser/js/jasmine-html.js +681 -0
  179. package/test/browser/runner.html +109 -0
  180. package/test/browser/runner.js +92 -0
  181. package/test/browser/sample/appinfo.sample.js +15 -0
  182. package/test/browser/sample/console.html +429 -0
  183. package/test/browser/sample/css/smoothness/images/animated-overlay.gif +0 -0
  184. package/test/browser/sample/css/smoothness/images/ui-bg_flat_0_aaaaaa_40x100.png +0 -0
  185. package/test/browser/sample/css/smoothness/images/ui-bg_flat_75_ffffff_40x100.png +0 -0
  186. package/test/browser/sample/css/smoothness/images/ui-bg_glass_55_fbf9ee_1x400.png +0 -0
  187. package/test/browser/sample/css/smoothness/images/ui-bg_glass_65_ffffff_1x400.png +0 -0
  188. package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_dadada_1x400.png +0 -0
  189. package/test/browser/sample/css/smoothness/images/ui-bg_glass_75_e6e6e6_1x400.png +0 -0
  190. package/test/browser/sample/css/smoothness/images/ui-bg_glass_95_fef1ec_1x400.png +0 -0
  191. package/test/browser/sample/css/smoothness/images/ui-bg_highlight-soft_75_cccccc_1x100.png +0 -0
  192. package/test/browser/sample/css/smoothness/images/ui-icons_222222_256x240.png +0 -0
  193. package/test/browser/sample/css/smoothness/images/ui-icons_2e83ff_256x240.png +0 -0
  194. package/test/browser/sample/css/smoothness/images/ui-icons_454545_256x240.png +0 -0
  195. package/test/browser/sample/css/smoothness/images/ui-icons_888888_256x240.png +0 -0
  196. package/test/browser/sample/css/smoothness/images/ui-icons_cd0a0a_256x240.png +0 -0
  197. package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.css +1175 -0
  198. package/test/browser/sample/css/smoothness/jquery-ui-1.10.1.custom.min.css +5 -0
  199. package/test/browser/sample/img/loading.gif +0 -0
  200. package/test/browser/sample/js/jquery-1.9.1.js +9597 -0
  201. package/test/browser/sample/js/jquery-ui-1.10.1.custom.js +14903 -0
  202. package/test/browser/sample/js/jquery-ui-1.10.1.custom.min.js +6 -0
  203. package/test/browser/sample/s3upload.html +111 -0
  204. package/test/browser.spec.coffee +207 -0
  205. package/test/config.spec.coffee +202 -0
  206. package/test/credential_provider_chain.spec.coffee +90 -0
  207. package/test/credentials.spec.coffee +452 -0
  208. package/test/endpoint.spec.coffee +80 -0
  209. package/test/event_listeners.spec.coffee +493 -0
  210. package/test/helpers.coffee +150 -0
  211. package/test/http_request.spec.coffee +55 -0
  212. package/test/json/builder.spec.coffee +129 -0
  213. package/test/json/parser.spec.coffee +108 -0
  214. package/test/metadata_service.spec.coffee +54 -0
  215. package/test/model/api.spec.coffee +67 -0
  216. package/test/model/shape.spec.coffee +23 -0
  217. package/test/node_http_client.spec.coffee +40 -0
  218. package/test/param_validator.spec.coffee +456 -0
  219. package/test/protocol/json.spec.coffee +167 -0
  220. package/test/protocol/query.spec.coffee +191 -0
  221. package/test/protocol/rest.spec.coffee +237 -0
  222. package/test/protocol/rest_json.spec.coffee +255 -0
  223. package/test/protocol/rest_xml.spec.coffee +329 -0
  224. package/test/query/query_param_serializer.spec.coffee +327 -0
  225. package/test/region_config.spec.coffee +50 -0
  226. package/test/request.spec.coffee +316 -0
  227. package/test/resource_waiter.spec.coffee +89 -0
  228. package/test/response.spec.coffee +81 -0
  229. package/test/sequential_executor.spec.coffee +118 -0
  230. package/test/service.spec.coffee +230 -0
  231. package/test/services/cloudfront.spec.coffee +44 -0
  232. package/test/services/cloudsearchdomain.spec.coffee +23 -0
  233. package/test/services/dynamodb.spec.coffee +32 -0
  234. package/test/services/ec2.spec.coffee +78 -0
  235. package/test/services/elastictranscoder.spec.coffee +43 -0
  236. package/test/services/glacier.spec.coffee +61 -0
  237. package/test/services/rds.spec.coffee +38 -0
  238. package/test/services/route53.spec.coffee +77 -0
  239. package/test/services/s3.spec.coffee +538 -0
  240. package/test/services/simpledb.spec.coffee +12 -0
  241. package/test/services/sqs.spec.coffee +130 -0
  242. package/test/services/sts.spec.coffee +72 -0
  243. package/test/services/swf.spec.coffee +6 -0
  244. package/test/signers/presign.spec.coffee +36 -0
  245. package/test/signers/s3.spec.coffee +297 -0
  246. package/test/signers/v2.spec.coffee +68 -0
  247. package/test/signers/v4.spec.coffee +135 -0
  248. package/test/util.spec.coffee +510 -0
  249. package/test/xml/builder.spec.coffee +529 -0
  250. package/test/xml/parser.spec.coffee +587 -0
  251. package/lib/services/simpledb.js +0 -15
@@ -0,0 +1,287 @@
1
+ # @title Configuring Web Identity Federation in the Browser
2
+
3
+ # Configuring Web Identity Federation in the Browser
4
+
5
+ This guide will walk through the steps required to configure your application
6
+ and vend federated credentials using trusted identity providers such
7
+ as [Login with Amazon](http://login.amazon.com/),
8
+ [Facebook](https://www.facebook.com/about/login/), or
9
+ [Google](https://developers.google.com/+/features/sign-in). In short, you will
10
+ want to:
11
+
12
+ 1. Register an application with the identity provider
13
+ 2. Create an IAM role for the identity provider
14
+ 3. Setup permissions for the IAM role
15
+ 4. Use the identity provider's SDK to get an access token after logging in
16
+ 5. Use the AWS SDK for JavaScript to get temporary credentials to your application
17
+
18
+ You can find more information about web identity federation in the
19
+ [AWS Security Token Service documentation](http://docs.aws.amazon.com/STS/latest/UsingSTS/CreatingWIF.html).
20
+
21
+ ## 1. Register an application with the identity provider
22
+
23
+ The first step is to register an application with the provider you are
24
+ interested in using. In order to do this, visit the identity provider through
25
+ the URLs above. You will be asked to provide some information that identifies
26
+ your application, and, in some cases, identifies the author of the application.
27
+ This is to ensure that the identity provider knows whom it is handing off its
28
+ user information to. In each case, you will get an application ID after you
29
+ have registered the application. This ID will be used to configure user roles.
30
+
31
+ ## 2. Create an IAM role for the identity provider
32
+
33
+ Once you have the application ID, you can visit the Roles section of the
34
+ [IAM console](https://console.aws.amazon.com/iam) to create a new role. Click
35
+ the "Create New Role" button and use the "Role for Web Identity Provider Access"
36
+ radio button when configuring the role. This will ask for the identity provider
37
+ and application ID that you got when you registered your application.
38
+
39
+ **Note** that you can also provide other constraints to the role, like scoping
40
+ the role to specific user IDs. If your role is providing write permissions
41
+ to your resources, you should make sure that you have correctly scoped this
42
+ to users with the correct privileges, otherwise any user with an Amazon,
43
+ Facebook, or Google identity will be able to modify resources in your
44
+ application.
45
+
46
+ ## 3. Setup permissions for the IAM role
47
+
48
+ <p class="note">
49
+ If you are configuring permissions for an Amazon S3 bucket, you may also
50
+ need to configure CORS. See the
51
+ <a href="#Cross-Origin_Resource_Sharing__CORS_">last section in this chapter</a>
52
+ for details on configuring CORS for your bucket.
53
+ </p>
54
+
55
+ The next step of the role creation wizard will ask you to configure permissions
56
+ for the resources you want to expose. This is where you would allow access to
57
+ specific operations on specific resources. You can use the policy generator
58
+ provided in the wizard to easily manage these permissions. You can also read
59
+ more about how to configure policies in the
60
+ [IAM documentation](http://docs.aws.amazon.com/IAM/latest/UserGuide/PoliciesOverview.html).
61
+
62
+ After you have configured permissions you will now have an IAM role. You can
63
+ view the details pane of the role to get the role ARN. Store this value for
64
+ later, as you will use it at the end of this guide to setup authentication in
65
+ the SDK.
66
+
67
+ ## 4. Use the identity provider's SDK to get an access token after logging in
68
+
69
+ For the next step, you will setup the login action for your application,
70
+ which will rely on the identity provider's SDK. In order to setup the relevant
71
+ SDK code in your application, you can visit the documentation for your
72
+ identity provider. In each case you will want to download and install a
73
+ JavaScript SDK that allows users to login either by OAuth or OpenID. We will
74
+ see examples of this in step 6.
75
+
76
+ To get the SDK for your identity provider, you can visit the following
77
+ web-specific documentation pages which will guide you through the process
78
+ of downloading and configuring the relevant JavaScript code to allow users
79
+ to login to your application:
80
+
81
+ 1. [Login with Amazon](http://login.amazon.com/website)
82
+ 2. [Facebook Login](https://developers.facebook.com/docs/reference/javascript/)
83
+ 3. [Google+ Sign-In](https://developers.google.com/+/web/signin/)
84
+
85
+ ## 5. Use the AWS SDK for JavaScript to get temporary credentials
86
+
87
+ After you have configured your application, roles, and resource permissions,
88
+ it is now time to write the code that you will use in your application to get
89
+ temporary credentials. These credentials will be provided through the AWS
90
+ Security Token Service using web identity federation. Users will login to
91
+ the identity provider using the SDK code setup in the previous step, which
92
+ will get them an access token. Using the IAM role ARN and the access token from
93
+ your provider, you will setup the `AWS.WebIdentityCredentials` helper object in
94
+ the SDK like so:
95
+
96
+ ```javascript
97
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
98
+ RoleArn: 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>',
99
+ ProviderId: 'graph.facebook.com|www.amazon.com', // Omit this for Google
100
+ WebIdentityToken: ACCESS_TOKEN
101
+ });
102
+
103
+ // You can now load service objects. Note that any objects created before
104
+ // setting the global config.credentials property will not have the
105
+ // credentials copied over.
106
+
107
+ var s3 = new AWS.S3;
108
+ ```
109
+
110
+ <p class="note">The <code>ProviderId</code> parameter should be set to null
111
+ or omitted when configuring web identity federation through Google.
112
+ </p>
113
+
114
+ Remember, the `ACCESS_TOKEN` value is the access token you got from your
115
+ identity provider.
116
+
117
+ Note that you can also create the `AWS.WebIdentityCredentials` object before
118
+ retrieving the access token. This will allow you to create service objects
119
+ that depend on credentials before loading the access token. To do this,
120
+ simply create the credentials object without the `WebIdentityToken` parameter
121
+ and add it in later:
122
+
123
+ ```javascript
124
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
125
+ RoleArn: 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>',
126
+ ProviderId: 'graph.facebook.com|www.amazon.com' // Omit this for Google
127
+ });
128
+
129
+ // Create a service object
130
+ var s3 = new AWS.S3;
131
+ ```
132
+
133
+ In the callback from the identity provider's SDK with the access token:
134
+
135
+ ```javascript
136
+ AWS.config.credentials.params.WebIdentityToken = accessToken;
137
+ ```
138
+
139
+ ## 6. Putting it all together
140
+
141
+ <p class="note">
142
+ These examples must be run from a http:// or https:// host scheme to
143
+ ensure that the identity provider is able to redirect back to your
144
+ application.
145
+ </p>
146
+
147
+ Here is some example code using various identity providers to get credentials
148
+ into your application. Most identity providers will have a similar setup
149
+ step that involves loading the respective SDK, logging in, and receiving
150
+ an access token.
151
+
152
+ ### Login with Amazon
153
+
154
+ The following code shows how to use Login with Amazon as an identity provider
155
+ with the SDK:
156
+
157
+ <a href="#" id="login">
158
+ <img border="0" alt="Login with Amazon"
159
+ src="https://images-na.ssl-images-amazon.com/images/G/01/lwa/btnLWA_gold_156x32.png"
160
+ width="156" height="32" />
161
+ </a>
162
+ <div id="amazon-root"></div>
163
+ <script type="text/javascript">
164
+ var s3 = null;
165
+ var appId = 'AMAZON_APP_ID';
166
+ var roleArn = 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>';
167
+
168
+ window.onAmazonLoginReady = function() {
169
+ amazon.Login.setClientId(appId); // set app ID
170
+
171
+ document.getElementById('login').onclick = function() {
172
+ amazon.Login.authorize({scope: 'profile'}, function(response) {
173
+ if (!response.error) { // logged in
174
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
175
+ RoleArn: roleArn,
176
+ ProviderId: 'www.amazon.com',
177
+ WebIdentityToken: response.access_token
178
+ });
179
+
180
+ s3 = new AWS.S3;
181
+
182
+ console.log('You are now logged in.');
183
+ } else {
184
+ console.log('There was a problem logging you in.');
185
+ }
186
+ });
187
+ };
188
+ };
189
+
190
+ (function(d) {
191
+ var a = d.createElement('script'); a.type = 'text/javascript';
192
+ a.async = true; a.id = 'amazon-login-sdk';
193
+ a.src = 'https://api-cdn.amazon.com/sdk/login1.js';
194
+ d.getElementById('amazon-root').appendChild(a);
195
+ })(document);
196
+ </script>
197
+
198
+ ### Facebook Login
199
+
200
+ The following code shows how to setup Facebook as an identity provider with
201
+ the SDK:
202
+
203
+ <button id="login">Login</button>
204
+ <div id="fb-root"></div>
205
+ <script type="text/javascript">
206
+ var s3 = null;
207
+ var appId = 'FACEBOOK_APP_ID';
208
+ var roleArn = 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>';
209
+
210
+ window.fbAsyncInit = function() {
211
+ // init the FB JS SDK
212
+ FB.init({appId: appId});
213
+
214
+ document.getElementById('login').onclick = function() {
215
+ FB.login(function (response) {
216
+ if (response.authResponse) { // logged in
217
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
218
+ RoleArn: roleArn,
219
+ ProviderId: 'graph.facebook.com',
220
+ WebIdentityToken: response.authResponse.accessToken
221
+ });
222
+
223
+ s3 = new AWS.S3;
224
+
225
+ console.log('You are now logged in.');
226
+ } else {
227
+ console.log('There was a problem logging you in.');
228
+ }
229
+ });
230
+ };
231
+ };
232
+
233
+ // Load the FB JS SDK asynchronously
234
+ (function(d, s, id){
235
+ var js, fjs = d.getElementsByTagName(s)[0];
236
+ if (d.getElementById(id)) {return;}
237
+ js = d.createElement(s); js.id = id;
238
+ js.src = "//connect.facebook.net/en_US/all.js";
239
+ fjs.parentNode.insertBefore(js, fjs);
240
+ }(document, 'script', 'facebook-jssdk'));
241
+ </script>
242
+
243
+ ### Google
244
+
245
+ The following code shows how to setup Google as an identity provider with
246
+ the SDK:
247
+
248
+ <p class="note">The access token used for web identity federation from Google
249
+ is found in the <code>response.id_token</code> property, not
250
+ <code>access_token</code> like other identity providers.
251
+ </p>
252
+
253
+ <span
254
+ id="login"
255
+ class="g-signin"
256
+ data-height="short"
257
+ data-callback="loginToGoogle"
258
+ data-cookiepolicy="single_host_origin"
259
+ data-requestvisibleactions="http://schemas.google.com/AddActivity"
260
+ data-scope="https://www.googleapis.com/auth/plus.login">
261
+ </span>
262
+ <script type="text/javascript">
263
+ var s3 = null;
264
+ var appId = 'GOOGLE_APP_ID';
265
+ var roleArn = 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>';
266
+
267
+ document.getElementById('login').setAttribute('data-clientid', appId);
268
+ function loginToGoogle(response) {
269
+ if (!response.error) {
270
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
271
+ RoleArn: roleArn, WebIdentityToken: response.id_token
272
+ });
273
+
274
+ s3 = new AWS.S3;
275
+
276
+ console.log('You are now logged in.');
277
+ } else {
278
+ console.log('There was a problem logging you in.');
279
+ }
280
+ }
281
+
282
+ (function() {
283
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
284
+ po.src = 'https://apis.google.com/js/client:plusone.js';
285
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
286
+ })();
287
+ </script>
@@ -0,0 +1,218 @@
1
+ # @title Configuring the SDK in the Browser
2
+
3
+ # Configuring the SDK in the Browser
4
+
5
+ The SDK requires two settings to be configured in order to make requests,
6
+ a region for the service(s) being used, and credentials to access the resources.
7
+
8
+ In addition to configuring these settings in the application, you may also have
9
+ to configure permissions on the resources you control on AWS. We will discuss
10
+ the basics of this at the end of this chapter.
11
+
12
+ ## The Global Configuration Object (`AWS.config`)
13
+
14
+ By default, you can set global configuration by updating the `AWS.config` object with
15
+ new settings. The most common settings are:
16
+
17
+ 1. `credentials` &mdash; the credentials object that contains authentication keys.
18
+ 2. `region` &mdash; to set the region for requests
19
+ 3. `sslEnabled` &mdash; whether SSL is enabled or not
20
+ 4. `maxRetries` &mdash; to control the number of retries for a request
21
+ 5. `logger` &mdash; a logger object to write debug information to. Set to `console`
22
+ to get logging information about service requests.
23
+
24
+ More configuration settings can be found in the
25
+ [API reference documentation](http://docs.aws.amazon.com/AWSJavaScriptSDK/latest/frames.html).
26
+
27
+ If you have multiple service objects that work in different regions, you can
28
+ look at the [Service-Specific Configuration](#Service-Specific_Configuration)
29
+ section below to see how to pass the region to each individual service.
30
+
31
+ ### Loading Credentials in the Client's Browser
32
+
33
+ <p class="note">Never hard-code credentials to your web application unless the
34
+ credentials are scoped to an
35
+ <a href="http://aws.amazon.com/iam/faqs/#What_is_a_user">IAM user</a>
36
+ with read-only permissions to very specific resources. Remember that when
37
+ developing a client-side application in the browser, all source code you
38
+ write is downloaded and available to be inspected by your users, so you
39
+ should never put secrets inside of your application.
40
+ </p>
41
+
42
+ Credentials are the most important thing you need to set when using any AWS SDK.
43
+ Credentials can be set globally on the `AWS.config` object or per service by
44
+ passing the credential information to the service object directly.
45
+
46
+ There are a couple of ways to load credentials. Here they are, in order of
47
+ recommendation:
48
+
49
+ 1. Using web identity federation to authenticate users
50
+ 2. Hard-coded in your application
51
+
52
+ We recommend you not hard-code your AWS credentials in your application;
53
+ however, it is reasonable to temporarily hard-code credential information
54
+ in small personal scripts or for testing purposes. It is also sometimes
55
+ necessary to hard-code **read-only** credentials in your application.
56
+
57
+ #### Using Web Identity Federation to Authenticate Users
58
+
59
+ The recommended way to authorize users of your application to access
60
+ AWS resources is to set up federated login through a trusted third-party
61
+ identity provider. This feature is known as Web Identity Federation. Amazon
62
+ Web Services currently supports authenticating users using web identity
63
+ federation through 3 identity providers:
64
+
65
+ 1. [Login with Amazon](http://login.amazon.com/)
66
+ 2. [Facebook](https://www.facebook.com/about/login/)
67
+ 3. [Google](https://developers.google.com/+/)
68
+
69
+ After you select an identity provider, you must register an application with
70
+ the provider, create an IAM role, and setup permissions for this role. The
71
+ IAM role you create will be used to grant the permissions you configured
72
+ to the users that login through the respective identity provider. For example,
73
+ you can setup a role that allows users who login through Facebook to get read
74
+ access to a specific S3 bucket that you control.
75
+
76
+ Once you have an IAM role with configured privileges and an application
77
+ registered with your identity provider of choice, you can setup the SDK to
78
+ get credentials for this role using the following credential management helper
79
+ code:
80
+
81
+ ```javascript
82
+ AWS.config.credentials = new AWS.WebIdentityCredentials({
83
+ RoleArn: 'arn:aws:iam::<AWS_ACCOUNT_ID>:role/<WEB_IDENTITY_ROLE_NAME>',
84
+ ProviderId: 'graph.facebook.com|www.amazon.com', // this is null for Google
85
+ WebIdentityToken: ACCESS_TOKEN
86
+ });
87
+ ```
88
+
89
+ The `ProviderId` parameter will depend on the identity provider you choose,
90
+ and the `WebIdentityToken` will be the access token retrieved from the login
91
+ process with the identity provider. You can visit the following
92
+ web-specific documentation pages in order to find out how to configure and
93
+ retrieve access tokens for users logging in through each respective identity
94
+ provider:
95
+
96
+ 1. [Login with Amazon](http://login.amazon.com/website)
97
+ 2. [Facebook Login](https://developers.facebook.com/docs/reference/javascript/)
98
+ 3. [Google+ Sign-In](https://developers.google.com/+/web/signin/)
99
+
100
+
101
+ A full look at how to setup web identity federation for your application can
102
+ be found in the {file:browser-configuring-wif.md Configuring Web Identity Federation}
103
+ chapter of this guide. You can also read the
104
+ [AWS Security Token Service documentation](http://docs.aws.amazon.com/STS/latest/UsingSTS/CreatingWIF.html)
105
+ on creating temporary credentials using web identity federation, or see the
106
+ [Web Identity Federation Playground](https://web-identity-federation-playground.s3.amazonaws.com/index.html),
107
+ which provides a hands-on look at how this process works.
108
+
109
+ #### Hard-Coding Credentials
110
+
111
+ <p class="note">If you hard-code credentials in your application, ensure that
112
+ the credentials you are vending in your application are scoped to an
113
+ <a href="http://aws.amazon.com/iam/faqs/#What_is_a_user">IAM user</a>
114
+ with read-only permissions to very specific resources. Remember that when
115
+ hard-coding credentials in your application, you are allowing all of your
116
+ users access to the secret key in plain text.
117
+ </p>
118
+
119
+ You can hard-code credentials by passing the credential information to the
120
+ configuration object using `AWS.config.update()`:
121
+
122
+ ```javascript
123
+ AWS.config.update({accessKeyId: 'akid', secretAccessKey: 'secret'});
124
+ ```
125
+
126
+ ### Setting the Region
127
+
128
+ The AWS SDK for JavaScript doesn't select the region by default. You can choose
129
+ a region by setting the `region` property on the global configuration object,
130
+ or by setting it per-service. The following code sets the region globally for
131
+ all subsequent service objects:
132
+
133
+ ```javascript
134
+ AWS.config.region = 'us-west-1';
135
+ ```
136
+
137
+ ## Service-Specific Configuration
138
+
139
+ Occasionally, you might want to apply configuration only to one service.
140
+ For instance, you want to use multiple EC2 objects in different regions.
141
+ You can do this by passing configuration data directly to the service object
142
+ constructor:
143
+
144
+ ```javascript
145
+ var s3 = new AWS.S3({region: 'ap-southeast-2', maxRetries: 15});
146
+ ```
147
+
148
+ Note that the constructor takes all of the same configuration data as the
149
+ `AWS.config` object described above, including credential information.
150
+
151
+ ## Cross-Origin Resource Sharing (CORS)
152
+
153
+ Cross-Origin Resource Sharing, or CORS, is a security feature of modern web
154
+ browsers that allow them to negotiate which domains they will allow to make
155
+ requests against which external websites or services. This is an important
156
+ feature to keep in mind when developing applications with the AWS SDK for
157
+ JavaScript in the browser, since most requests to resources will be sent to an
158
+ external domain (the endpoint for the given AWS service). If your browser or
159
+ environment enforces CORS security, you will need to configure CORS with the
160
+ service.
161
+
162
+ Fortunately, only Amazon S3 requires explicit configuration for CORS. Other
163
+ services only require that the request is signed using authentication keys
164
+ that have permissions on the resource (discussed above).
165
+
166
+ ### Configuring CORS for an Amazon S3 Bucket
167
+
168
+ In order to configure an Amazon S3 bucket to use CORS, you can visit the
169
+ [Amazon S3 console](https://console.aws.amazon.com/s3), click on the properties
170
+ tab of the bucket you want to configure, and then click "Edit CORS
171
+ Configuration" in the Permissions section. A set of
172
+ [sample configurations](http://docs.aws.amazon.com/AmazonS3/latest/dev/cors.html#how-do-i-enable-cors)
173
+ are provided in the S3 documentation.
174
+
175
+ A quick CORS configuration sample is shown below. This sample allows a user to
176
+ view, add, remove, or update objects inside of a bucket from any external domain,
177
+ though it is recommended that you scope the "AllowedOrigin" to the domain that
178
+ your website runs from (you can specify "*" to allow any origin).
179
+
180
+ <?xml version="1.0" encoding="UTF-8"?>
181
+ <CORSConfiguration xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
182
+ <CORSRule>
183
+ <AllowedOrigin>https://example.org</AllowedOrigin>
184
+ <AllowedMethod>HEAD</AllowedMethod>
185
+ <AllowedMethod>GET</AllowedMethod>
186
+ <AllowedMethod>PUT</AllowedMethod>
187
+ <AllowedMethod>POST</AllowedMethod>
188
+ <AllowedMethod>DELETE</AllowedMethod>
189
+ <AllowedHeader>*</AllowedHeader>
190
+ <ExposeHeader>ETag</ExposeHeader>
191
+ <ExposeHeader>x-amz-meta-custom-header</ExposeHeader>
192
+ </CORSRule>
193
+ </CORSConfiguration>
194
+
195
+ **Note** that this does *not* authorize the user to perform any actions on the
196
+ bucket, it simply enables the browser's security model to allow a request
197
+ to S3. Actual permissions for the user must be configured either via bucket
198
+ permissions, or IAM role level permissions.
199
+
200
+ You can use `ExposeHeader` to allow the SDK to read response headers returned
201
+ from S3. For example, if you want to read the "ETag" header from a PUT
202
+ or multipart upload, you will need to include the above `ExposeHeader` tag
203
+ in your configuration. Due to a limitation in browser security layers, the SDK
204
+ can only access headers that have been exposed through CORS configuration.
205
+ Note that if you set metadata on the object, these values are returned as
206
+ headers with the prefix `x-amz-meta-`, i.e., `x-amz-meta-my-custom-header`,
207
+ and must also be exposed in the same way.
208
+
209
+ ### When CORS is Not Required
210
+
211
+ CORS does not always need to be configured explicitly. In some environments,
212
+ like local desktop or mobile devices, CORS may not be enforced, and configuring
213
+ it is not necessary.
214
+
215
+ Furthermore, if you host your application from within S3 and access
216
+ resources from "*.s3.amazonaws.com" (or a specific regional endpoint), your
217
+ requests will not be accessing an external domain and therefore will not
218
+ require CORS. CORS will still be used for services besides S3 in this case.