charlesbihis / actionscript-oauth2 Goto Github PK
View Code? Open in Web Editor NEWAn ActionScript 3 library for interfacing with OAuth 2.0 services.
Home Page: http://charlesbihis.github.io/actionscript-oauth2/
License: Other
An ActionScript 3 library for interfacing with OAuth 2.0 services.
Home Page: http://charlesbihis.github.io/actionscript-oauth2/
License: Other
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.
[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,
It would be nice if the OAuth2 class could fire off events to notify of StageWebView events. In particular a Load URI event and a Finished With StageWebView event. This is necessary because the StageWebView itself does not have a Load URI event. It only has a Change and Changing events. Knowing when a URI begins loading is necessary to implement a loading indicator. Also a Finished with StageWebView event would be nice to have so the app can close the StageWebView as soon as possible. This is particularly the case with installed apps, where the SageWebView will stay open awkwardly after completing the login, while the oauth token is retrieved in the second step.
Hi,
How can I update my state in twitter using this SDK?
Thanks
if your using "urn:ietf:wg:oauth:2.0:oob" as the redirect URL, the auth code is returned in the title of the response page.
So instead of parsing the redirect url in LocationChangeEvent.LOCATION_CHANGE. You need to parse the authorizationCodeGrant.stageWebView.title in Event.COMPLETE.
It would be nice if the OAuth2 class could fire off events to notify of StageWebView events. In particular a Load URI event and a Finished With StageWebView event. This is necessary because the StageWebView itself does not have a Load URI event. It only has a Change and Changing events. Knowing when a URI begins loading is necessary to implement a loading indicator. Also a Finished with StageWebView event (or a GetAuthCodeEvent) would be nice to have so the app can close the StageWebView as soon as possible. This is particularly the case with installed apps, where the SageWebView will stay open awkwardly after completing the login, while the oauth token is retrieved in the second step.
Thanks for taking a look at this issue. But I would like to clarify why these changes would be helpful. First off these are really only issues that would become serious when a user has a slow or unreliable internet connection. For this case I have been implementing a loading indicator, so the user knows there is no need to keep pressing submit. Also, at least in the case of the Google Installed App OAuth use case, the result page that shows once an auth code is obtained but before an access token, if it stays visible for more than a second it is misleading and confusing to the user because it instructs the user to copy and paste the code. This is why it would be nice to close the StageWebView as soon as possible.
As to the difference between locationChange, locationChanging and loadURL:
locationChange is fired when the page load is complete.
locationChanging is fired when page starts loading but is not fired when loadURL initiates that change. From the docs: "A locationChanging event is only dispatched when the location change is initiated through HTML content or code running inside the StageWebView object,such as when a user clicks a link. "
To implement a loading indicator, I have found that I need to know when loadURL is called, because no event is raised otherwise.
With regard to listening for a GetAccessTokenEvent:
The GetAccessTokenEvent is not fired when the auth code is obtained. But rather there is a delay between when the auth code is obtained and the access token is granted while a call to the tokenEndpoint is made. Usually this is fast and unnoticeable, but in the case of slow or unreliable internet it can cause the auth code result page to linger, leading to confusion. It would be nice to know when the auth code process is complete so the WebStageView can be closed.
Admittedly these are not urgent issues, but these improvements will enable an enhanced user experience.
The Project currently references a source path that is not available.
This is irritating because downloading and deploying the swc is not working "out of the box"
I realize adobe has made stageWebView only available in AIR and not the web player. This seems like an important part. I found a possible alternative https://github.com/talltyler/HTMLWrapper but it doesn't look very promising. Is there a way to get this working on desktops without writing a browser in AS3?
Thanks
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.