Pergunta

So I am building an iOS with instagram integration. I registered my app with instagram and have everything working so far. When the user clicks the ADD ACCOUNT button, I load the instagram auth url (https://instagram.com/oauth/authorize/?client_id=CLIENT-ID&redirect_uri=REDIRECT-URI&response_type=token) into a webview and the instagram login page appears.

I can then successfully login, my redirect then redirects correctly, and I can then exchange the code for an access token, close the webview, and display an alert saying that login was successful. But when the user clicks the ADD ACCOUNT button again and the webview loads the auth url, instead of seeing the instagram login page, it automatically authorizes and the successful login alert appears.

Is the webview caching something? How would I prevent this?

Foi útil?

Solução

try clear caches and cookies

clear caches:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

to remove cookies check those two questions:

How to delete all cookies of UIWebView?

Delete cookies UIWebView

Outras dicas

In Swift :

  class func clearInstagramCookies() {

    let cookieStore = NSHTTPCookieStorage.sharedHTTPCookieStorage()
    guard let cookies = cookieStore.cookies where cookies.count > 0 else { return }

    for cookie in cookies {
      if cookie.domain == "www.instagram.com" || cookie.domain == "api.instagram.com" {
        cookieStore.deleteCookie(cookie)
      }
    }
  }

You must clear cookies of Instagram if you want to log the user out or if you need the sign-in page to appear again in UIWebView.

EDIT : Swift3

    let cookieStore = HTTPCookieStorage.shared
    guard let cookies = cookieStore.cookies, cookies.count > 0 else { return }

    for cookie in cookies {
        if cookie.domain == "www.instagram.com" || cookie.domain == "api.instagram.com" {
            cookieStore.deleteCookie(cookie)
        }
    }

You can clear session and cookies by:

[[NSURLCache sharedURLCache] removeAllCachedResponses];

    for(NSHTTPCookie *cookie in [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookies]) {

        [[NSHTTPCookieStorage sharedHTTPCookieStorage] deleteCookie:cookie];

    }

it took me sometime to figure this out too.

I am working on an web app, so i got no option of clearing the cache. It seems however got very little to do with caching or cookies. Once your Instagram app is authorised by the particular user, pointing to that Auth URL will just automatically bring you back to your redirect URL.

Your user will have to manual revoke your apps rights at https://instagram.com/accounts/manage_access to be able to view the login screen again.

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top