Search in sources :

Example 1 with CookieSyncManager

use of android.webkit.CookieSyncManager in project Klyph by jonathangerbaud.

the class Util method clearCookies.

public static void clearCookies(Context context) {
    // Edge case: an illegal state exception is thrown if an instance of
    // CookieSyncManager has not be created.  CookieSyncManager is normally
    // created by a WebKit view, but this might happen if you start the
    // app, restore saved state, and click logout before running a UI
    // dialog in a WebView -- in which case the app crashes
    @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Example 2 with CookieSyncManager

use of android.webkit.CookieSyncManager in project facebook-api-android-maven by avianey.

the class Utility method clearCookiesForDomain.

private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if CookieSyncManager
    // has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();
    CookieManager cookieManager = CookieManager.getInstance();
    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }
    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Example 3 with CookieSyncManager

use of android.webkit.CookieSyncManager in project generic-oauth2-login-for-android by wareninja.

the class Utils method clearCookies.

public static void clearCookies(Context context) {
    // Edge case: an illegal state exception is thrown if an instance of 
    // CookieSyncManager has not be created.  CookieSyncManager is normally
    // created by a WebKit view, but this might happen if you start the 
    // app, restore saved state, and click logout before running a UI 
    // dialog in a WebView -- in which case the app crashes
    @SuppressWarnings("unused") CookieSyncManager cookieSyncMngr = CookieSyncManager.createInstance(context);
    CookieManager cookieManager = CookieManager.getInstance();
    cookieManager.removeAllCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Example 4 with CookieSyncManager

use of android.webkit.CookieSyncManager in project facebook-android-sdk by facebook.

the class WebLoginMethodHandler method onComplete.

protected void onComplete(LoginClient.Request request, Bundle values, FacebookException error) {
    LoginClient.Result outcome;
    e2e = null;
    if (values != null) {
        // Actual e2e we got from the dialog should be used for logging.
        if (values.containsKey(ServerProtocol.DIALOG_PARAM_E2E)) {
            e2e = values.getString(ServerProtocol.DIALOG_PARAM_E2E);
        }
        try {
            AccessToken token = createAccessTokenFromWebBundle(request.getPermissions(), values, getTokenSource(), request.getApplicationId());
            outcome = LoginClient.Result.createTokenResult(loginClient.getPendingRequest(), token);
            // Ensure any cookies set by the dialog are saved
            // This is to work around a bug where CookieManager may fail to instantiate if
            // CookieSyncManager has never been created.
            CookieSyncManager syncManager = CookieSyncManager.createInstance(loginClient.getActivity());
            syncManager.sync();
            saveCookieToken(token.getToken());
        } catch (FacebookException ex) {
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, ex.getMessage());
        }
    } else {
        if (error instanceof FacebookOperationCanceledException) {
            outcome = LoginClient.Result.createCancelResult(loginClient.getPendingRequest(), "User canceled log in.");
        } else {
            // Something went wrong, don't log a completion event since it will skew timing
            // results.
            e2e = null;
            String errorCode = null;
            String errorMessage = error.getMessage();
            if (error instanceof FacebookServiceException) {
                FacebookRequestError requestError = ((FacebookServiceException) error).getRequestError();
                errorCode = String.format(Locale.ROOT, "%d", requestError.getErrorCode());
                errorMessage = requestError.toString();
            }
            outcome = LoginClient.Result.createErrorResult(loginClient.getPendingRequest(), null, errorMessage, errorCode);
        }
    }
    if (!Utility.isNullOrEmpty(e2e)) {
        logWebLoginCompleted(e2e);
    }
    loginClient.completeAndValidate(outcome);
}
Also used : FacebookOperationCanceledException(com.facebook.FacebookOperationCanceledException) AccessToken(com.facebook.AccessToken) CookieSyncManager(android.webkit.CookieSyncManager) FacebookException(com.facebook.FacebookException) FacebookServiceException(com.facebook.FacebookServiceException) FacebookRequestError(com.facebook.FacebookRequestError)

Example 5 with CookieSyncManager

use of android.webkit.CookieSyncManager in project facebook-android-sdk by facebook.

the class Utility method clearCookiesForDomain.

private static void clearCookiesForDomain(Context context, String domain) {
    // This is to work around a bug where CookieManager may fail to instantiate if
    // CookieSyncManager has never been created.
    CookieSyncManager syncManager = CookieSyncManager.createInstance(context);
    syncManager.sync();
    CookieManager cookieManager = CookieManager.getInstance();
    String cookies = cookieManager.getCookie(domain);
    if (cookies == null) {
        return;
    }
    String[] splitCookies = cookies.split(";");
    for (String cookie : splitCookies) {
        String[] cookieParts = cookie.split("=");
        if (cookieParts.length > 0) {
            String newCookie = cookieParts[0].trim() + "=;expires=Sat, 1 Jan 2000 00:00:01 UTC;";
            cookieManager.setCookie(domain, newCookie);
        }
    }
    cookieManager.removeExpiredCookie();
}
Also used : CookieSyncManager(android.webkit.CookieSyncManager) CookieManager(android.webkit.CookieManager)

Aggregations

CookieSyncManager (android.webkit.CookieSyncManager)10 CookieManager (android.webkit.CookieManager)9 Context (android.content.Context)1 Editor (android.content.SharedPreferences.Editor)1 Uri (android.net.Uri)1 AccessToken (com.facebook.AccessToken)1 FacebookException (com.facebook.FacebookException)1 FacebookOperationCanceledException (com.facebook.FacebookOperationCanceledException)1 FacebookRequestError (com.facebook.FacebookRequestError)1 FacebookServiceException (com.facebook.FacebookServiceException)1