Open Website From App And Redirect Back - swift3

We have an app that requires a user to make a payment. We have a third party provider that handles the payments. On our website, when the user makes a payment they get directed to the payment portal on the third party's website and after payment, they get redirected back to our website.
I have been tasked to implement the same thing in our iOS Swift 3 app. I have an idea of what I want to do but I am not quite sure how to do it. I started by thinking that I could open the user's browser with a POST request (I know now that I can't) and then using Universal Linking, grab the redirect with the app once payment is complete.
So since I cannot do POST requests on the user's browser, I thought I would implement a UIWebView in my app. Basically I have the code to do this. My question is. How do I capture the redirect from the UiWebView? As far as I can tell, upon successful payment the UIWebView will stay active and the page will redirect, showing our website inside of our app. This is not what I want.
Can anyone explain a better way of doing this? No Code required, but will be greatly appreciated.

Yes, Its possible and many apps are doing the same.
There are various methods to do it but What I am doing, I can share.
I am opening payment page in webview and after success on payment page. The page is redirecting to Success page with SuccessURL. When SuccessURL/FailedURL(Predefined) started loading, I take user back to native app.
func webView(webView: UIWebView, shouldStartLoadWithRequest request: NSURLRequest, navigationType: UIWebViewNavigationType) -> Bool {
if request.url == "sucessURL" {
//do whatever you want
return false
}
if request.url == "failedURL" {
////do whatever you want
return false
}
else {
return true
}
}

Related

Delete cookies from python WebKit.WebView

I have a PyGtk app with an embedded WebKit.WebView. Users login to our service through the embedded browser and they can make payments in PayPal page.
This app is used by different users in the same session, so the problem is that PayPal bakes cookies and remembers the email of the last payment.
I just want to complete the payment and delete PayPal-related cookies from my WebView but I cannot find any documentation about removing cookies.
To re-create the webView is not an option because my web page is quite heavy to load.
Any help would be highly appreciated
I figured out by myself.
First I added a custom cookiejar. This allows me to handle the cookies
from gi.repository import Soup
cookiejar = Soup.CookieJarText.new("cookies/biscottini.txt", False)
cookiejar.set_accept_policy(Soup.CookieJarAcceptPolicy.ALWAYS)
session = gi.repository.WebKit.get_default_session()
session.add_feature(cookiejar)
Then I found the Soup class structure and wrote down this simple snippet to clear the cookies (there's also a filter to delete only PayPal cookies)
def clearCookies(deleteAll=False):
for cookie in cookiejar.all_cookies():
if deleteAll or ('paypal' in cookie.get_domain().lower()):
cookiejar.delete_cookie(cookie)
I now have a problem though: after clearing PayPal's cookies if I try to make a payment, I get the error: "Message Corrupt"

Facebook graph API manual login flow in iOS returns error_reason user_denied

I'm trying to create manual Facebook login in iOS using UIWebView for the login flow
for learning propose. I know there is framework for this.
Any way I'm starting with :
First
https://www.facebook.com/dialog/oauth?client_id=80xxxxx03174&redirect_uri=http://www.
facebook.com/connect/login_success.html&scope=user_friends&response_type=token&display=
touch
Redirects me to :
https://m.facebook.com/v2.0/dialog/oauth?redirect_uri=http%3A%2F%2Fwww.facebook.com%
2Fconnect%2Flogin_success.html&scope=user_friends&response_type=token&client_id=
80xxxxx03174
Redirects me again to error
https://m.facebook.com/login.php?skip_api_login=1&api_key=8072xxxx03174&signed_next=1&
next=https%3A%2F%2Fm.facebook.com%2Fv2.0%2Fdialog%2Foauth%3Fredirect_uri%3Dhttp%253A%252F%
252Fwww.facebook.com%252Fconnect%252Flogin_success.html%26scope%3Duser_friends%
26response_type%3Dtoken%26client_id%3D8072922xxx174%26ret%3Dlogin&cancel_uri=http%3A%2F%
2Fwww.facebook.com%2Fconnect%2Flogin_success.html%3Ferror%3Daccess_denied%26error_code%
3D200%26error_description%3DPermissions%2Berror%26error_reason%3Duser_denied%23_%3D_&
display=touch&_rdr
Now the user and the app do exists.
I tested the first ( no'1 ) URL in the browser and it returns me the access_token back
UPDATE:
I found out the number 3 request is invoking twice and in the first time I present the WebView and then in the second time it sends this. I try to present the same web view that is already presented and I got exception.
So way do this request send it self twice?

Cannot save cookies for JMETER

I'm new with Jmeter and by default sorry for dump question.
I want to start with the most basic testing for web site. I want to login to application and navigate to specific page. Basically, that is it for now.
I was fighting with this issue but unfortunately I cannot save cookies properly. I use the following test scenario:
However, after I start to run scenario I can see that login was executed successfully, but navigation on page redirect to Login page.
It seems that cookies were not actually saved.
Please any advice. If you require any additional information I'll provide everything what is needed.
What makes you say login did not work or work ?
Why don't you first look in View Results Tree at first "Http Request login" sampler response to check that login was successful ?
To see if Cookies are transmitted check Request Tab in View Results Tree to see if Cookies are transmitted.
From what you show it seems you are playing login twice, check your Thread Group for number of iterations ? if you set more than 1, maybe your application does not allow double login.

Facebook FB.logout not working in IE

I am working on a django website which also allows users to sign in using their Facebook account. The login works fine, however I am not able to logout using Internet Explorer. The code seems to work fine on Firefox and Chrome.
Heres the code
function logoutFBUser()
{
//logout user from website and Facebook and reload
alert ("called FB logout");
if (FB.getAuthResponse())
{
alert ("has auth response");
FB.logout(function(response)
{
window.location.href = '/accounts/logout?next=/';
});
alert ("logged out of FB and redirected");
}
else
{
alert(" no auth response");
window.location.href = '/accounts/logout?next=/';
}
}
In Firefox, I get the alert of has auth response, however in IE, I get the alert no auth response. If I only use FB.logout without FB.getAuthResponse then the function hangs when it hits FB.logout.
What am I missing?
Finally solved this. I debugged into the javascript for FB.logout and for some reason it doesnt have the access_token which is why the call to FB.logout fails. Researching the Facebook documentation led me to this URL which I used for the logout process on my website successfully
Logoutlink from Facebook Documentation
https://www.facebook.com/logout.php?next=REDIRECT_URI&access_token=LOGGEDINUSER_ACCESS_TOKEN
Needless to say, I am using this on the serverside, so no need to use javascript any more.
Please refer Facebook Authentication documentation for more information.
http://developers.facebook.com/docs/authentication/
Thanks for all the help

Facebook Connect application inside iframe not working in IE7

I am building a Facebook Connect application that runs inside a Google gadget. Being a gadget means that the application runs inside an iframe. Inside the application, there is a form that allows registered users to post comments. The submission is made using AJAX, but I get the same results with a normal form. The problem is that I need to get the user's facebook id. In Firefox, it works fine, but on Internet Explorer 7, I get the following error:
'A session key is required for calling this method'
I believe that this is due to the way IE handles third-party cookies, because if I go to Internet options / Privacy / Advanced, and check Override automatic cookie handling and accept all cookies, it works fine. I cannot pass the Facebook id from the javascript, because anyone could tamper it.
EDIT: If I open the content of the iframe directly, the app works fine. The problem is really due to the IFRAME and IE security model.
What am I doing something wrong? How can I work around this problem?
Have you tried adding a P3P policy ?
If the response setting the cookie has a compact policy, IE will use this to determine whether or not to allow the 3rd party cookie..
I solved the same problem by modifying how I check if the user was logged in on the PHP page following a FB connect login.
So, they login to FB Connect with IE7.
Next and subsequent page loads where I need to verify they are indeed logged into FaceBook I used the following code (note that $facebook->require_login() and other functions did not work - they returned null only in IE 7):
// Validate from Facebook that session is valid and user is logged in.
require_once 'facebook/facebook.php';
$facebook = new Facebook(YourAppsAPIKeyPublic, YourAppsAPIKeySecret);
$facebook->api_client->session_key = $this->userAPISessionKey;
$fb_user_id = $facebook->api_client->users_getLoggedInUser();
The $fb_user_id should now have a valid FaceBook user ID.
Regarding privacy policy and facebook connect + IE 7:
Although this didn't work for me it appears to work for others. in HTAccess:
Header append P3P "CP=\"HONK\""
or in PHP files:
header('P3P: CP="CAO PSA OUR"');
or
header('P3P: CP="HONK"');
reference: http://forum.developers.facebook.com/viewtopic.php?id=28636
ASP.NET:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
HttpContext.Current.Response.AddHeader("p3p", "CP=\"CAO PSA OUR\"");
}
I found a work-around that works, although it is a bit ugly: when the user clicks the 'login' button, it opens a popup that comes from my own site and which contains the Facebook Connect login button. After the user logs in, I close the popup and reload the iframe.
This is really ugly because It opens two popups, but at least it works. I will detect whether cookies are enabled using javascript and if they are enabled, I will skip the first popup.
I'm still open to better solutions...
Edit: Facebook now uses a "fake" popup inside my popup, instead of opening another window. Now I only have one popup which is ok for me.
you may want to see this thread also, which is created under facebook developer platform
http://forum.developers.facebook.com/viewtopic.php?id=452