New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Login failure using webview #163
Comments
This is related to using a useragent, but don't know what the expectation is.
|
Endpoints can only be called through an Instagram app user agent. |
I suggest sticking to the default one, leaving it |
But when I use nil then I see android advertisement and apple will not approve my app like this. @sbertix |
Unfortunately that's the supported user agent because it works, if you manage to find one that works just as well without displaying the ad, let us know, considering the ad cannot be removed through JavaScript injection either. @MariaJsn Beware though that apps built with SwiftyInsta are definitely not App Store safe: you gain control of an entire user's account, no tokens, no authorization, no nothing, which is a big no no for the Review guidelines, other than the Instagram terms and conditions, meaning your app is gonna be rejected at one point, if not at first, because of this. Ad or no ad. |
use this user agent for webView: |
@TheM4hd1 @sbertix I used this user agent but I can login failed again. My code: let login = LoginWebViewController(userAgent: "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148", completionHandler: { controller, result in
|
I tried it on iOS 12.0, iPhone 7, Simulator and iOS 13.3, iPhone XS, Real Device |
@TheM4hd1 so my code is wrong? also I insert the code inside Loginwebwiew class init method and it shows Google play advertisement. Is it possible can you show me your code which has working one?
|
again, leave everything as default,
you can hard code the user agent here, leave everything as default, Clean Build the project and build again, no changes applies if you don't clean build. if this worked for you probably there's a bug in initializers and we need to double check the codes.but I tried this and worked without any issue. |
Custom user agents in |
This comment has been minimized.
This comment has been minimized.
Do you mind printing the login error you get? @MariaJsn // deal with authentication response.
guard let (response, _) = try? result.get() else { return print("Login failed.") }
//print("Login successful.")
// persist cache safely in the keychain for logging in again in the future.
guard let key = response.persist() else { return print("`Authentication.Response` could not be persisted.") } Write switch result {
case .failure(let error): print(error)
case .success(let response):
guard let key = response.0.persist() else { print("No key.") }
print(key)
} And paste in here the output of |
@sbertix the error is |
Yep, so same as above, meaning the issue is not in I'll test some more and update you if I find something. |
This comment has been minimized.
This comment has been minimized.
Ok… so it's not an issue of the user agent per se. It seems like any custom user configuration causes a checkpoint to the user. {
"errorBody" : "Please log back in.",
"errorTitle" : "You've Been Logged Out",
"logoutReason" : 3,
"message" : "login_required",
"status" : "fail"
} The cookies are set and everything, but when they're used to fetch anything from a given endpoint the user is forced to log out. |
Cause I feel like he either has that device he was testing, so it's somehow linked to his profile, or he used that user agent before Instagram changed things. Again though: this is not a problem with |
@TheM4hd1 |
actually I was using an older version of this is the file, I replaced it with current version ( a few changes requires for error handling ), and it worked well. //
// LoginWebView.swift
// SwiftyInsta
//
// Created by Stefano Bertagno on 07/19/2019.
// Copyright © 2019 Mahdi. All rights reserved.
//
#if os(iOS)
import UIKit
import WebKit
// MARK: Views
@available(iOS 11, *)
public class LoginWebView: WKWebView, WKNavigationDelegate {
/// Called when reaching the end of the login flow.
/// You should probably hide the `InstagramLoginWebView` and notify the user with an activity indicator.
public var didReachEndOfLoginFlow: (() -> Void)?
/// Called once the flow is completed.
var completionHandler: ((Result<[HTTPCookie], Error>) -> Void)!
// MARK: Init
public init(frame: CGRect,
configuration: WKWebViewConfiguration = .init(),
didReachEndOfLoginFlow: (() -> Void)? = nil) {
// update the process pool.
let copy = configuration.copy() as? WKWebViewConfiguration ?? WKWebViewConfiguration()
copy.processPool = WKProcessPool()
// init login.
self.didReachEndOfLoginFlow = didReachEndOfLoginFlow
super.init(frame: frame, configuration: copy)
self.navigationDelegate = self
}
@available(*, unavailable, message: "use `init(frame:configuration:didReachEndOfLoginFlow:didSuccessfullyLogIn:completionHandler:)` instead.")
private override init(frame: CGRect, configuration: WKWebViewConfiguration) {
fatalError("init(frame:, configuration:) has been removed")
}
@available(*, unavailable)
public required init?(coder: NSCoder) {
fatalError("init(coder:) has not been implemented")
}
// MARK: Log in
func authenticate(completionHandler: @escaping (Result<[HTTPCookie], Error>) -> Void) {
// update completion handler.
self.completionHandler = completionHandler
// wipe all cookies and wait to load.
deleteAllCookies { [weak self] in
guard let me = self else { return }
guard let url = URL(string: "https://www.instagram.com/accounts/login/") else {
return
}
// in some iOS versions, use-agent needs to be different.
// this use-agent works on iOS 11.4 and iOS 12.0+
// but it won't work on lower versions.
// me.customUserAgent = ["(Linux; Android 5.0; iPhone Build/LRX21T)",
// "AppleWebKit/537.36 (KHTML, like Gecko)",
// "Chrome/70.0.3538.102 Mobile Safari/537.36"].joined(separator: " ")
me.customUserAgent = "Mozilla/5.0 (iPhone; CPU iPhone OS 13_3 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Mobile/15E148"
// load request.
me.load(URLRequest(url: url))
}
}
// MARK: Clean cookies
private func fetchCookies() {
configuration.websiteDataStore.httpCookieStore.getAllCookies { [weak self] in
self?.completionHandler?(.success($0))
}
}
private func deleteAllCookies(completionHandler: @escaping () -> Void) {
HTTPCookieStorage.shared.removeCookies(since: Date.distantPast)
WKWebsiteDataStore.default().removeData(ofTypes: WKWebsiteDataStore.allWebsiteDataTypes(),
modifiedSince: .distantPast,
completionHandler: completionHandler)
}
// MARK: Navigation delegate
public func webView(_ webView: WKWebView, didFinish navigation: WKNavigation!) {
guard webView.url?.absoluteString == "https://www.instagram.com/" else { return }
// notify user.
didReachEndOfLoginFlow?()
// fetch cookies.
fetchCookies()
}
}
#endif |
Wasn't this the early Either way, either by starting with this snippet or with |
yes I guess that's the version. |
Except So, like I said, the issue is not related to tl;dr: again, the |
that's what I meant, changing |
Yep, but the problem of the feed not appearing in the new version has nothing to do with it: it's actually a feature, and a good one. If you used a custom user agent in the current version but replaced row 118 of |
This does not work either. It returns the same exact error as the new version @TheM4hd1.
As of lately, accounts marked as We would need to find a new way to channel requests, move forward from the user agent used for them below, and we'd still be very likely to fail.
tl;dr: nothing we can do. It's Instagram's fault."Fixes"
DisclaimerTo anyone reading this: |
I'm receiving the following error message on
try? result.get()
using instagramcontroller, any idea why @TheM4hd1 ?The text was updated successfully, but these errors were encountered: