Skip to content

token retrieved but GetAccessTokenEvent empty #8

Description

@bobrokrol

Project made with Apache flex 4.15 Air 20 for Desktop Windows 7
I did simple testing app using example code for retrieveing token and I have few issues.

  • if StageWebVew initialized with usenative false (new StageWebView(false)) doesn't work at all I see just web view loading error
  • if I initiate it with usenative = true it seens to be worked. but with errors. I recieved few GetAccessTokenEvent but both with null's inside. It's my log:

[trace] 2016/2/28 1:34:40.26 [INFO] com.adobe.protocols.oauth2.OAuth2 Initiating getAccessToken() with authorization code grant type workflow
[trace] 2016/2/28 1:34:40.30 [INFO] com.adobe.protocols.oauth2.OAuth2 Loading auth URL: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=1005094869546-eso7913kn7uc0s39ha343c3e7460baek.apps.googleusercontent.com&redirect_uri=http://localhost&scope=email profile&state=
[trace] 2016/2/28 1:34:40.679 [INFO] com.adobe.protocols.oauth2.OAuth2 Loading URL: https://accounts.google.com/o/oauth2/auth?response_type=code&client_id=1005094869546-eso7913kn7uc0s39ha343c3e7460baek.apps.googleusercontent.com&redirect_uri=http://localhost&scope=email profile&state=
[trace] 2016/2/28 1:34:41.114 [INFO] com.adobe.protocols.oauth2.OAuth2 Auth URL loading complete after 1085ms
[trace] 2016/2/28 1:34:42.544 [INFO] com.adobe.protocols.oauth2.OAuth2 Loading URL: https://accounts.google.com/o/oauth2/approval?as=-6f751a3b996912c&hl=en&pageId=none&xsrfsign=APsBz4gAAAAAVtI5l3Vnbcd7KGhiCt6EbQxBV6oei8WF
[trace] 2016/2/28 1:34:42.636 [INFO] com.adobe.protocols.oauth2.OAuth2 Loading URL: http://localhost/?code=4/T_Ej7lu-smhtAJrjQYiIVQmskdV1_FiFxaRQ0DcwXTE#
[trace] 2016/2/28 1:34:42.636 [INFO] com.adobe.protocols.oauth2.OAuth2 Redirect URI encountered (http://localhost). Extracting values from path.
[trace] 2016/2/28 1:34:42.636 [DEBUG] com.adobe.protocols.oauth2.OAuth2 Authorization code: 4/T_Ej7lu-smhtAJrjQYiIVQmskdV1_FiFxaRQ0DcwXTE#
[trace] 2016/2/28 1:34:42.639 [ERROR] com.adobe.protocols.oauth2.OAuth2 Error occurred with StageWebView: [ErrorEvent type="error" bubbles=false cancelable=false eventPhase=2 text="Load error: 0x800C0014." errorID=3228]
[trace] 2016/2/28 1:34:42.665 [INFO] com.adobe.protocols.oauth2.OAuth2 Loading URL: https://accounts.google.com/o/oauth2/approval?as=-6f751a3b996912c&hl=en&pageId=none&xsrfsign=APsBz4gAAAAAVtI5l3Vnbcd7KGhiCt6EbQxBV6oei8WF
[trace] 2016/2/28 1:34:42.695 [INFO] com.adobe.protocols.oauth2.OAuth2 Auth URL loading complete after 2666ms
[trace] 2016/2/28 1:34:42.952 [DEBUG] com.adobe.protocols.oauth2.OAuth2 Access token: ya29.lQJCxnMw56fPUHqkHWS2cgDQGXLQSRvQVUvRSVYSpwEKdx_nOK78qTomomIv8oGSQw
[trace] Your access token value is: null

Here is my testing code:

private function addAccount_mouseDownHandler(event:MouseEvent):void
        {
            var stageWebView:StageWebView = new StageWebView(true);
            stageWebView.stage = stage;
            stageWebView.viewPort = new Rectangle(0, 0, 500, 500);
            var oauth2:OAuth2 = new OAuth2("https://accounts.google.com/o/oauth2/auth",
                    "https://accounts.google.com/o/oauth2/token", LogSetupLevel.ALL);
            var grant:IGrantType = new AuthorizationCodeGrant(stageWebView,                     // the StageWebView object for which to display the user consent screen
                    "1005094869546-eso7913kn7uc0s39ha343c3e7460baek.apps.googleusercontent.com",          // your client ID
                    "tcAPaOZj16HcbG5eEQlLKwYX",      // your client secret
                    "http://localhost",       // your redirect URI
                    "email profile",              // (optional) your scope
                    "");             // (optional) your state

            oauth2.addEventListener(GetAccessTokenEvent.TYPE, onGetAccessToken);

            oauth2.getAccessToken(grant);

        }

        function onGetAccessToken(getAccessTokenEvent:GetAccessTokenEvent):void
        {
            if (getAccessTokenEvent.errorCode == null && getAccessTokenEvent.errorMessage == null)
            {
                // success!
                trace("Your access token value is: " + getAccessTokenEvent.accessToken);
            }
            else
            {
                // fail :(
            }
        } 

Looks like getAccessTokenEvent is owerwritten somwhere inside nested functions.
I did some rought fix here
com/adobe/protocols/oauth2/OAuth2.as:329


                    {
                        var response:Object = com.adobe.serialization.json.JSON.decode(event.target.data);
                        log.debug("Access token: " + response.access_token);
                        var getAccessTokenEvent2 = new GetAccessTokenEvent();
                        getAccessTokenEvent2.parseAccessTokenResponse(response);
                    }  // try statement
                    catch (error:JSONParseError)
                    {
                        getAccessTokenEvent2.errorCode = "com.adobe.serialization.json.JSONParseError";
                        getAccessTokenEvent2.errorMessage = "Error parsing output from access token response";
                    }  // catch statement

                    dispatchEvent(getAccessTokenEvent2);

so now it works for my situation,

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions