Java Code Examples for com.sina.weibo.sdk.utils.SecurityHelper

The following examples show how to use com.sina.weibo.sdk.utils.SecurityHelper. These examples are extracted from open source projects. 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 Project: letv   Source File: SsoHandler.java    License: Apache License 2.0 6 votes vote down vote up
private boolean startSingleSignOn(String ssoPackageName, String ssoActivityName) {
    boolean bSucceed = true;
    Intent intent = new Intent();
    intent.setClassName(ssoPackageName, ssoActivityName);
    intent.putExtras(this.mWebAuthHandler.getAuthInfo().getAuthBundle());
    intent.putExtra("_weibo_command_type", 3);
    intent.putExtra("_weibo_transaction", String.valueOf(System.currentTimeMillis()));
    intent.putExtra("aid", Utility.getAid(this.mAuthActivity, this.mAuthInfo.getAppKey()));
    if (!SecurityHelper.validateAppSignatureForIntent(this.mAuthActivity, intent)) {
        return false;
    }
    String aid = Utility.getAid(this.mAuthActivity, this.mAuthInfo.getAppKey());
    if (!TextUtils.isEmpty(aid)) {
        intent.putExtra("aid", aid);
    }
    try {
        this.mAuthActivity.startActivityForResult(intent, this.mSSOAuthRequestCode);
    } catch (ActivityNotFoundException e) {
        bSucceed = false;
    }
    return bSucceed;
}
 
Example 2
Source Project: MiBandDecompiled   Source File: SsoHandler.java    License: Apache License 2.0 6 votes vote down vote up
private boolean startSingleSignOn(String s, String s1)
{
    boolean flag = true;
    Intent intent = new Intent();
    intent.setClassName(s, s1);
    intent.putExtras(mWeibo.getAuthInfo().getAuthBundle());
    intent.putExtra("_weibo_command_type", 3);
    intent.putExtra("_weibo_transaction", String.valueOf(System.currentTimeMillis()));
    if (!SecurityHelper.validateAppSignatureForIntent(mAuthActivity, intent))
    {
        return false;
    }
    try
    {
        mAuthActivity.startActivityForResult(intent, mSSOAuthRequestCode);
    }
    catch (ActivityNotFoundException activitynotfoundexception)
    {
        flag = false;
    }
    mAuthActivity.getApplicationContext().unbindService(mConnection);
    return flag;
}
 
Example 3
Source Project: LoginSharePay   Source File: BaseHandler.java    License: Apache License 2.0 5 votes vote down vote up
protected void startClientAuth(int requestCode) {
    try {
        WbAppInfo wbAppInfo = WeiboAppManager.getInstance(this.mAuthFragment.getContext()).getWbAppInfo();
        Intent intent = new Intent();
        intent.setClassName(wbAppInfo.getPackageName(), wbAppInfo.getAuthActivityName());
        intent.putExtras(WbSdk.getAuthInfo().getAuthBundle());
        intent.putExtra("_weibo_command_type", 3);
        intent.putExtra("_weibo_transaction", String.valueOf(System.currentTimeMillis()));
        intent.putExtra("aid", Utility.getAid(this.mAuthFragment.getContext(), WbSdk.getAuthInfo().getAppKey()));
        if (!SecurityHelper.validateAppSignatureForIntent(this.mAuthFragment.getContext(), intent)) {
            return;
        }

        this.fillExtraIntent(intent, requestCode);

        try {
            this.mAuthFragment.startActivityForResult(intent, this.ssoRequestCode);
        } catch (Exception var5) {
            if (this.authListener != null) {
                this.authListener.onFailure(new WbConnectErrorMessage());
            }

            this.couldNotStartWbSsoActivity();
        }
    } catch (Exception var6) {
        ;
    }

}
 
Example 4
Source Project: LoginSharePay   Source File: BaseHandler.java    License: Apache License 2.0 5 votes vote down vote up
public void authorizeCallBack(int requestCode, int resultCode, Intent data) {
    if ('胍' == requestCode) {
        if (resultCode == -1) {
            if (!SecurityHelper.checkResponseAppLegal(this.mAuthFragment.getContext(), WeiboAppManager.getInstance(this.mAuthFragment.getContext()).getWbAppInfo(), data)) {
                this.authListener.onFailure(new WbConnectErrorMessage("your install weibo app is counterfeit", "8001"));
                return;
            }

            String error = Utility.safeString(data.getStringExtra("error"));
            String error_type = Utility.safeString(data.getStringExtra("error_type"));
            String error_description = Utility.safeString(data.getStringExtra("error_description"));
            LogUtil.d("WBAgent", "error: " + error + ", error_type: " + error_type + ", error_description: " + error_description);
            if (TextUtils.isEmpty(error) && TextUtils.isEmpty(error_type) && TextUtils.isEmpty(error_description)) {
                Bundle bundle = data.getExtras();
                Oauth2AccessToken accessToken = Oauth2AccessToken.parseAccessToken(bundle);
                if (accessToken != null && accessToken.isSessionValid()) {
                    LogUtil.d("WBAgent", "Login Success! " + accessToken.toString());
                    AccessTokenKeeper.writeAccessToken(this.mAuthFragment.getContext(), accessToken);
                    this.authListener.onSuccess(accessToken);
                }
            } else if (!"access_denied".equals(error) && !"OAuthAccessDeniedException".equals(error)) {
                LogUtil.d("WBAgent", "Login failed: " + error);
                this.authListener.onFailure(new WbConnectErrorMessage(error_type, error_description));
            } else {
                LogUtil.d("WBAgent", "Login canceled by user.");
                this.authListener.cancel();
            }
        } else if (resultCode == 0) {
            if (data != null) {
                this.authListener.cancel();
            } else {
                this.authListener.cancel();
            }
        }
    }

}
 
Example 5
Source Project: letv   Source File: SsoHandler.java    License: Apache License 2.0 4 votes vote down vote up
public void authorizeCallBack(int requestCode, int resultCode, Intent data) {
    LogUtil.d(TAG, "requestCode: " + requestCode + ", resultCode: " + resultCode + ", data: " + data);
    String error;
    Bundle bundle;
    Oauth2AccessToken accessToken;
    if (requestCode == this.mSSOAuthRequestCode) {
        if (resultCode == -1) {
            if (SecurityHelper.checkResponseAppLegal(this.mAuthActivity, this.mWeiboInfo, data)) {
                error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE);
                if (error == null) {
                    error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_TYPE);
                }
                if (error == null) {
                    bundle = data.getExtras();
                    accessToken = Oauth2AccessToken.parseAccessToken(bundle);
                    if (accessToken == null || !accessToken.isSessionValid()) {
                        LogUtil.d(TAG, "Failed to receive access token by SSO");
                        this.mWebAuthHandler.anthorize(this.mAuthListener);
                        return;
                    }
                    LogUtil.d(TAG, "Login Success! " + accessToken.toString());
                    this.mAuthListener.onComplete(bundle);
                } else if (error.equals("access_denied") || error.equals("OAuthAccessDeniedException")) {
                    LogUtil.d(TAG, "Login canceled by user.");
                    this.mAuthListener.onCancel();
                } else {
                    String description = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_DESCRIPTION);
                    if (description != null) {
                        error = new StringBuilder(String.valueOf(error)).append(NetworkUtils.DELIMITER_COLON).append(description).toString();
                    }
                    LogUtil.d(TAG, "Login failed: " + error);
                    this.mAuthListener.onWeiboException(new WeiboDialogException(error, resultCode, description));
                }
            }
        } else if (resultCode != 0) {
        } else {
            if (data != null) {
                LogUtil.d(TAG, "Login failed: " + data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE));
                this.mAuthListener.onWeiboException(new WeiboDialogException(data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE), data.getIntExtra(NativeProtocol.BRIDGE_ARG_ERROR_CODE, -1), data.getStringExtra("failing_url")));
                return;
            }
            LogUtil.d(TAG, "Login canceled by user.");
            this.mAuthListener.onCancel();
        }
    } else if (requestCode != REQUEST_CODE_MOBILE_REGISTER) {
    } else {
        if (resultCode == -1) {
            bundle = data.getExtras();
            accessToken = Oauth2AccessToken.parseAccessToken(bundle);
            if (accessToken != null && accessToken.isSessionValid()) {
                LogUtil.d(TAG, "Login Success! " + accessToken.toString());
                this.mAuthListener.onComplete(bundle);
            }
        } else if (resultCode != 0) {
        } else {
            if (data != null) {
                LogUtil.d(TAG, "Login failed: " + data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE));
                error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE);
                if (error == null) {
                    error = data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_TYPE);
                }
                if (error != null) {
                    this.mAuthListener.onWeiboException(new WeiboDialogException(data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_BUNDLE), data.getIntExtra(NativeProtocol.BRIDGE_ARG_ERROR_CODE, -1), data.getStringExtra(NativeProtocol.BRIDGE_ARG_ERROR_DESCRIPTION)));
                    return;
                }
                return;
            }
            LogUtil.d(TAG, "Login canceled by user.");
            this.mAuthListener.onCancel();
        }
    }
}