*
* original :
* oauth2.js , <opendata@oucs.ox.ac.uk>
+ * https://github.com/ox-it/javascript-oauth2/blob/master/oauth2/oauth2.js
*
* @alias X.OAuth2
* @class OAuth2 サービスを定義し接続状況をモニタする。適宜にトークンのアップデートなどを行う
'redirectURI' : X.URL.cleanup( document.location.href ), // 専用の軽量ページを用意してもよいが、現在のアドレスでも可能
'scopes' : [ 'https://www.googleapis.com/auth/blogger' ],
'refreshMargin' : 300000,
+ // canuse
'authorizeWindowWidth' : 500,
'authorizeWindowHeight' : 500
}).listen( [ X.Event.NEED_AUTH, X.Event.CANCELED, X.Event.SUCCESS, X.Event.ERROR, X.Event.PROGRESS ], updateOAuth2State );
'Accept' : 'application/json',
'Content-Type' : 'application/x-www-form-urlencoded'
},
- 'test' : 'gadget'
+ 'test' : 'gadget' // canuse
} ).listenOnce( [ X_EVENT_SUCCESS, X_EVENT_ERROR ], this, X_Net_OAuth2_responceHandler );
this[ 'asyncDispatch' ]( { type : X_EVENT_PROGRESS, message : 'Start to refresh token.' } );
};
pair.oauth2State = 4;
+
+ if( pair.lazyRequests && pair.lazyRequests.length ){
+ X_NET_QUEUE_LIST.push.apply( X_NET_QUEUE_LIST, pair.lazyRequests );
+ pair.lazyRequests.length = 0;
+ };
+
this[ 'asyncDispatch' ]( { type : X_EVENT_SUCCESS, message : isRefresh ? 'Refresh access token success.' : 'Get new access token success.' } );
break;
function X_NET_OAUTH2_onXHR401Error( oauth2, e ){
var pair = this,
headers = e[ 'headers' ],
- xhr, bearerParams, headersExposed = false;
+ bearerParams, headersExposed = false;
if( X_OAuth2_getAuthMechanism( oauth2 ) !== 'param' ){
- xhr = X_NET_currentWrapper[ '_rawObject' ];
- headersExposed = !X_Net_XHR_createXDR || !!headers; // this is a hack for Firefox and IE
+ headersExposed = !X_NET_currentWrapper.isXDR || !!headers; // this is a hack for Firefox and IE
bearerParams = headersExposed && ( headers[ 'WWW-Authenticate' ] || headers[ 'www-authenticate' ] );
X_Type_isArray( bearerParams ) && ( bearerParams = bearerParams.join( '\n' ) );
};
// http://d.hatena.ne.jp/ritou/20110402/1301679908
- if ( bearerParams && bearerParams.indexOf( ' error=' ) === -1 ) {
+ if ( bearerParams && bearerParams.indexOf( ' error=' ) === -1 ) { // bearerParams.error == undefined
pair.oauth2State = 0;
oauth2[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH );
} else
pair.oauth2State = 3;
oauth2[ 'refreshToken' ]();
} else {
- //if (!headersExposed && !X_OAuth2_getRefreshToken( oauth2 )) {
X_OAuth2_removeAccessToken( oauth2 ); // It doesn't work any more.
pair.oauth2State = 0;
oauth2[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH );
};
function X_OAuth2_getAccessToken( that ){ return X_OAuth2_updateLocalStorage( '', that, 'accessToken' ); }
-function X_OAuth2_getRefreshToken( that){ return X_OAuth2_updateLocalStorage( '', that, 'refreshToken' ); }
+function X_OAuth2_getRefreshToken( that ){ return X_OAuth2_updateLocalStorage( '', that, 'refreshToken' ); }
function X_OAuth2_getAccessTokenExpiry( that ){ return parseInt( X_OAuth2_updateLocalStorage( '', that, 'tokenExpiry' ) ) || 0; }
function X_OAuth2_getAuthMechanism( that ){
// TODO use gadget | flash ...
// IE's XDomainRequest doesn't support sending headers, so don't try.
- return X_Net_XHR_createXDR ? 'param' : X_OAuth2_updateLocalStorage( '', that, 'AuthMechanism' );
+ return ( X_NET_currentWrapper === X_NET_XHRWrapper ) && X_Net_XHR_createXDR ? 'param' : X_OAuth2_updateLocalStorage( '', that, 'AuthMechanism' );
}
function X_OAuth2_setAccessToken( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'accessToken' , value); }
function X_OAuth2_setRefreshToken( that, value ){ X_OAuth2_updateLocalStorage( '+', that, 'refreshToken', value); }