You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@flex.apache.org by ah...@apache.org on 2017/04/21 16:35:46 UTC
[22/43] git commit: [flex-asjs] [refs/heads/dual] - Added bead to
pass authorisation credentials on in JS HTTP requests
Added bead to pass authorisation credentials on in JS HTTP requests
Project: http://git-wip-us.apache.org/repos/asf/flex-asjs/repo
Commit: http://git-wip-us.apache.org/repos/asf/flex-asjs/commit/9e4b62d4
Tree: http://git-wip-us.apache.org/repos/asf/flex-asjs/tree/9e4b62d4
Diff: http://git-wip-us.apache.org/repos/asf/flex-asjs/diff/9e4b62d4
Branch: refs/heads/dual
Commit: 9e4b62d435e3f3166ce710e551c6e78100f88df6
Parents: 65320f9
Author: Justin Mclean <jm...@apache.org>
Authored: Sun Apr 16 15:41:15 2017 +1000
Committer: Justin Mclean <jm...@apache.org>
Committed: Sun Apr 16 15:41:15 2017 +1000
----------------------------------------------------------------------
.../flex/net/beads/CORSCredentialsBead.as | 79 ++++++++++++++++++++
1 file changed, 79 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/flex-asjs/blob/9e4b62d4/frameworks/projects/Network/src/main/flex/org/apache/flex/net/beads/CORSCredentialsBead.as
----------------------------------------------------------------------
diff --git a/frameworks/projects/Network/src/main/flex/org/apache/flex/net/beads/CORSCredentialsBead.as b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/beads/CORSCredentialsBead.as
new file mode 100644
index 0000000..6a44c90
--- /dev/null
+++ b/frameworks/projects/Network/src/main/flex/org/apache/flex/net/beads/CORSCredentialsBead.as
@@ -0,0 +1,79 @@
+package org.apache.flex.net.beads {
+import org.apache.flex.core.IBead;
+import org.apache.flex.core.IStrand;
+import org.apache.flex.events.Event;
+import org.apache.flex.events.IEventDispatcher;
+
+COMPILE::SWF
+public class CORSCredentialsBead {
+ public function CORSCredentialsBead(withCredentials:Boolean = false) {
+ trace("Only needed for JavaScript HTTP Server calls");
+ }
+}
+
+/**
+ * Bead to allow passing on user authentication information in a XMLHttpRequest request.
+ *
+ * If you don't use this bead any cross domain calls that require user authentication
+ * (via say basic authentication or cookies) will fail.
+ *
+ * @productversion FlexJS 0.8
+ */
+COMPILE::JS
+public class CORSCredentialsBead implements IBead {
+
+ public function CORSCredentialsBead(withCredentials:Boolean = false) {
+ this.withCredentials = withCredentials;
+ }
+
+ private var _strand:IStrand;
+
+ /**
+ * Listen for a pre and post send event to modify if user credentials are passed.
+ *
+ * @productversion FlexJS 0.8
+ */
+ public function set strand(value:IStrand):void {
+ _strand = value;
+
+ IEventDispatcher(_strand).addEventListener("preSend", preSendHandler);
+ IEventDispatcher(_strand).addEventListener("postSend", postSendHandler);
+ }
+
+ /**
+ * Modify the HTTP request to pass credentials.
+ *
+ * @productversion FlexJS 0.8
+ */
+ protected function preSendHandler(event:Event):void {
+ (event.target.element as XMLHttpRequest).withCredentials = withCredentials;
+ }
+
+ /**
+ * Clean up event listeners.
+ *
+ * @productversion FlexJS 0.8
+ */
+ protected function postSendHandler(event:Event):void {
+ IEventDispatcher(_strand).removeEventListener("preSend", preSendHandler);
+ IEventDispatcher(_strand).removeEventListener("postSend", preSendHandler);
+ }
+
+ private var _withCredentials:Boolean = false;
+
+ /**
+ * Pass the user credentials or not.
+ *
+ * @productversion FlexJS 0.8
+ */
+ public function get withCredentials():Boolean
+ {
+ return _withCredentials;
+ }
+
+ public function set withCredentials(value:Boolean):void
+ {
+ _withCredentials = value;
+ }
+}
+}