com.sina.weibo.sdk.auth.WbAuthListener Java Examples

The following examples show how to use com.sina.weibo.sdk.auth.WbAuthListener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: WbLoginHelper.java    From SocialSdkLibrary with Apache License 2.0 6 votes vote down vote up
public void login(Activity activity, final OnLoginStateListener listener) {
    if (listener == null)
        return;
    mOnLoginListener = listener;
    justAuth(activity, new WbAuthListener() {
        @Override
        public void onSuccess(Oauth2AccessToken oauth2AccessToken) {
            getUserInfo(oauth2AccessToken);
        }

        @Override
        public void cancel() {
            listener.onState(null, LoginResult.cancelOf());
        }

        @Override
        public void onFailure(WbConnectErrorMessage msg) {
            listener.onState(null, LoginResult.failOf(SocialError.make(SocialError.CODE_SDK_ERROR, TAG + "#login#connect error," + msg.getErrorCode() + " " + msg.getErrorMessage())));
        }
    });
}
 
Example #2
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 5 votes vote down vote up
private void authorize(int requestCode, WbAuthListener listener, BaseHandler.AuthType authType) {
    this.resetIntentFillData();
    if (listener == null) {
        throw new RuntimeException("please set auth listener");
    } else {
        this.authListener = listener;
        if (authType == BaseHandler.AuthType.WebOnly) {
            if (listener != null) {
                this.startWebAuth();
            }

        } else {
            boolean onlyClientSso = false;
            if (authType == BaseHandler.AuthType.SsoOnly) {
                onlyClientSso = true;
            }

            if (this.isWbAppInstalled()) {
                this.startClientAuth(requestCode);
            } else if (onlyClientSso) {
                this.authListener.onFailure(new WbConnectErrorMessage());
            } else {
                this.startWebAuth();
            }

        }
    }
}
 
Example #3
Source File: WBHelper.java    From SocialHelper with Apache License 2.0 5 votes vote down vote up
private void initLoginListener() {
    wbAuthCallback = new WbAuthListener() {
        @Override
        public void onSuccess(Oauth2AccessToken oauth2AccessToken) {
            if (oauth2AccessToken.isSessionValid()) {
                loginResult = oauth2AccessToken;
                AccessTokenKeeper.writeAccessToken(activity, oauth2AccessToken);
                getUserInfo(oauth2AccessToken);
            } else {
                handler.sendEmptyMessage(GET_INFO_ERROR);
            }
        }

        @Override
        public void cancel() {
            if (loginCallback != null && activity != null) {
                loginCallback.socialError(activity.getString(R.string.social_cancel));
            }
        }

        @Override
        public void onFailure(WbConnectErrorMessage error) {
            if (loginCallback != null) {
                loginCallback.socialError(error.getErrorMessage());
            }
        }
    };
}
 
Example #4
Source File: WbLoginHelper.java    From SocialSdkLibrary with Apache License 2.0 5 votes vote down vote up
public void justAuth(final Activity activity, final WbAuthListener listener) {
    Oauth2AccessToken token = AccessToken.getToken(activity, mLoginTarget, Oauth2AccessToken.class);
    if (token != null && token.isSessionValid() && token.getExpiresTime() > System.currentTimeMillis()) {
        listener.onSuccess(token);
    } else {
        AccessToken.clearToken(activity, Target.LOGIN_WB);
        mSsoHandler.authorize(new WbAuthListener() {
            @Override
            public void onSuccess(Oauth2AccessToken oauth2AccessToken) {
                oauth2AccessToken.setBundle(null);
                SocialUtil.json("test", oauth2AccessToken.toString());
                AccessToken.saveToken(activity, mLoginTarget, oauth2AccessToken);
                listener.onSuccess(oauth2AccessToken);
            }

            @Override
            public void cancel() {
                listener.cancel();
            }

            @Override
            public void onFailure(WbConnectErrorMessage wbConnectErrorMessage) {
                listener.onFailure(wbConnectErrorMessage);
            }
        });
    }
}
 
Example #5
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
public void authorize(WbAuthListener listener) {
    this.authorize('胍', listener, BaseHandler.AuthType.ALL);
}
 
Example #6
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
public void authorizeClientSso(WbAuthListener listener) {
    this.authorize('胍', listener, BaseHandler.AuthType.SsoOnly);
}
 
Example #7
Source File: BaseHandler.java    From LoginSharePay with Apache License 2.0 4 votes vote down vote up
public void authorizeWeb(WbAuthListener listener) {
    this.authorize('胍', listener, BaseHandler.AuthType.WebOnly);
}