//{+oauth2"OAuth2 サービスの定義"(OAuth2外部サービスを定義し、認可プロセス・xhrの署名を自動化します)[+xhr]
-var X_NET_OAUTH2_detection = new Function( 'w', 'try{return w.location.search}catch(e){}' ),
- X_NET_OAUTH2_authorizationWindow,
+var X_NET_OAUTH2_authorizationWindow,
X_NET_OAUTH2_authorizationTimerID;
/**
/**
* 認可用 window をポップアップする。ポップアップブロックが働かないように必ず pointer event 内で呼ぶこと。
+ * <dl>
+ * <dt>1 : <dd>認可用 window がポップアップ中(自身)
+ * <dt>2 : <dd>コードを認可中
+ * <dt>3 : <dd>トークンのリフレッシュ中
+ * <dt>4 : <dd>接続
+ * <dt>5 : <dd>他のOAuth2サービスの認可用 window がポップアップ中
+ * </dl>
+ * @return {number}
*/
'requestAuth' : function(){
- var url, w, h;
+ var e = X_EventDispatcher_CURRENT_EVENTS[ X_EventDispatcher_CURRENT_EVENTS.length - 1 ],
+ w, h;
+
// TODO pointer event 内か?チェック
+ if( !e || !e[ 'pointerType' ] ){
+ alert( 'タッチイベント以外での popup! ' + ( e ? e.type : '' ) );
+ return;
+ };
+
// 二つ以上の popup を作らない
if( X_NET_OAUTH2_authorizationWindow ) return;
pair = X_Pair_get( this );
if( pair.net || pair.oauth2State ) return;
-
- url = pair[ 'authorizeEndpoint' ];
+
w = pair[ 'authorizeWindowWidth' ] || 500;
h = pair[ 'authorizeWindowHeight' ] || 500;
+ // TODO X.Util.Window
X_NET_OAUTH2_authorizationWindow = window.open(
- X_URL_create( url,
+ X_URL_create( pair[ 'authorizeEndpoint' ],
{
'response_type' : 'code',
'client_id' : pair[ 'clientID' ],
'redirect_uri' : pair[ 'redirectURI' ],
- 'scope' : ( pair[ 'scopes' ] || [] ).join(' ')
+ 'scope' : ( pair[ 'scopes' ] || [] ).join( ' ' )
}
),
'oauthauthorize',
this[ 'asyncDispatch' ]( X_EVENT_CANCELED );
} else
- if( search = X_NET_OAUTH2_detection( X_NET_OAUTH2_authorizationWindow ) ){
+ if( search = X_Script_try( X_Object_find, [ X_NET_OAUTH2_authorizationWindow, 'location>search' ] ) ){
pair = X_Pair_get( this );
- pair.code = X_URL_ParamToObj( search.slice( 1 ) )[ 'code' ];
+ pair.code = X_URL_paramToObj( search.slice( 1 ) )[ 'code' ];
if( 9 < X_UA[ 'IEHost' ] ){
X_NET_OAUTH2_authorizationWindow.close();
X_NET_OAUTH2_authorizationWindow = null;
X_NET_OAUTH2_authorizationTimerID = 0;
- return X_Callback_UN_LISTEN;
+ return X_CALLBACK_UN_LISTEN;
};
};
};
// http://d.hatena.ne.jp/ritou/20110402/1301679908
- if ( bearerParams && bearerParams.indexOf( ' error=' ) === -1 ) { // bearerParams.error == undefined
+ if( bearerParams && bearerParams.indexOf( ' error=' ) === -1 ){ // bearerParams.error == undefined
pair.oauth2State = 0;
oauth2[ 'asyncDispatch' ]( X_EVENT_NEED_AUTH );
} else
- if ((( bearerParams && bearerParams.indexOf( 'invalid_token' ) !== -1 ) || !headersExposed) && X_OAuth2_getRefreshToken( oauth2 ) ) {
+ if( ( ( bearerParams && bearerParams.indexOf( 'invalid_token' ) !== -1 ) || !headersExposed ) && X_OAuth2_getRefreshToken( oauth2 ) ){
X_OAuth2_removeAccessToken( oauth2 ); // It doesn't work any more.
pair.oauth2State = 3;
oauth2[ 'refreshToken' ]();
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_getAccessTokenExpiry( that ){ return parseInt( X_OAuth2_updateLocalStorage( '', that, 'tokenExpiry' ) ) || 0; }
+function X_OAuth2_getAccessTokenExpiry( that ){ return parseFloat( 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_currentWrapper === X_NET_XHRWrapper ) && X_Net_XHR_createXDR ? 'param' : X_OAuth2_updateLocalStorage( '', that, 'AuthMechanism' );
+ return ( X_NET_currentWrapper === X_XHR ) && X_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); }