WeChat Login Autorization is not happenning in Swift - ios

I am trying to Login my App with We\chat in iOS(swift).
1. I have added all the following:
[I have followed all the steps specified in this link][1]
[1]: How do I do authorization and login with WeChat using the iOS SDK? 2. In the AppDelegate.swift, I have added the code as:if authResp.code != nil {
let dict = ["response": authResp.code]
nc.post(name: NSNotification.Name(rawValue: "WeChatAuthCodeResp"), object: nil, userInfo: dict)
}
3. After this step: Wechat app asked for authorization, I allowed it, after that some link is loaded in mobile browser: but this is not loading, empty page is showing 4. I haven't got any response code in the function, provide me solution for this or any guidance to get the Authorization code 5. As soon as Login Button is clicked, It is communicating with We chat App, and a link is opening in a browser to get the authorization code. The link could not able to complete it in the browser. Kindly help me on getting the Authorization code

Related

How to get authorization code from google oauth2?

I got a task to perform google authentication. My task is like i should create a sign in with google button and after clicking it the authentication process should start and shows my details in the next view. I wrote code like this.
let url = URL(string: "https://accounts.google.com/o/oauth2/v2/auth?scope=email%20profile&response_type=code&state=security_token%3D138r5719ru3e1%26url%3Dhttps://oauth2.example.com/token&redirect_uri=someuri:/oauth2redirect&client_id=myclient id")!
and for the button i wrote function like
#IBAction func googleSignIn(_ sender: Any) {
UIApplication.shared.open(url, options: [:], completionHandler: nil)
}
I dont know how to get to get the authorization code so that i can send it back to get the access token. I sould not follow any steps provided in google to integrate my with google sign in also i should not use any pods. Anyone worked on it? please help me.

iOS - GitHub Firebase Authentication

I'm currently trying to implement GitHub Authentication via Firebase in an iOS app.
I've read through the docs and figured out what I have to do. I'm having trouble though, in implementing the communication between my app and the WebView where I authorize the application to get user's data. I currently have this code:
let url = urlComponents.url! // https://github.com/login/oauth/authorize + scope
// Not quite sure if I should use open(_:options:completionHandler:) to handle this operation.
guard UIApplication.shared.canOpenURL(url) else {
return
}
UIApplication.shared.open(url, options: [:], completionHandler: nil)
What this code does is bring the user to the browser with the GitHub authorization screen, type the password and then a blank screen shows up. Inspecting the URL in this blank screen, I've found out that it contains the parameter it should have, but I'm not quite sure how to pass this parameter to my code so I can proceed with the authentication.
Firebase doc says I should implement a Custom URL scheme to handle the OAuth callback, but I'm not sure how to do it.
Solved, solution was to edit GitHub's Authorization callback URL to have my custom URL scheme and then proceed through the documentation flow.

How do you update GoogleSign-In to work with the new Firebase Console and APIs?

So, I had everything working as of yesterday. Then I logged into my Firebase dashboard and there was a banner that suggested I try out the new Firebase console. "SURE! That sounds great" I thought.
Eight hours later, I cannot get Google Sign-In to work. Here is my GIDSignInDelegate method, which fires correctly and everything.
func signIn(signIn: GIDSignIn!,
didSignInForUser user: GIDGoogleUser!,
withError error: NSError!) {
if (error == nil) {
let authentication = user.authentication
let credential = FIRGoogleAuthProvider.credentialWithIDToken(authentication.idToken,
accessToken: authentication.accessToken)
FIRAuth.auth()?.signInWithCredential(credential, completion: nil)
} else {
// Don't assert this error it is commonly returned as nil
print("\(error.localizedDescription)")
}
}
The problem seems to be that this doesnt create an event for
FIRAuth.auth()!.addAuthStateDidChangeListener
which is in my app delegate.
When logging in with the Facebook API, it does fire the auth state change listener.
I have also tried with a completion block, the user is a GIDGoogleUser instead of an FIRUser which seems kinda weird, but I have no proof it would be a problem. Also, the error is nil. so it looks like the signInWithCredential is working, but the auth state change listener isnt firing.
The only thing I can think of is that there is a problem with the google sign-in part of the system as the new GoogleService-Info.plist I had to download from the Firebase Console has a different app ID than I had in my previous GoogleService-Info.plist. I tried replacing the new app id with my old one which didn't work at all. I then tried removing any reference to the old app id assuming that the new one integrates google sign in automatically. Still no luck.
Anyone had success updating?
I added "import FirebaseAuth" and it worked! I know the Firebase documentation didn't say to add this, but I decided to give it a try anyways.
You need to add "Web SDK Configuration". You still need to enter it even though you may only have iOS app!
Go to your "Auth" tab in the new Firebase console.
Click on "Google" under "sign in providers"
Hover over "Web SDK configuration (optional)", it will bring up the popover saying "Reuse a web client ID from an existing Google project. You can find your web client ID for existing projects by selecting your project and OAuth 2.0 entry on the Google API Console."
Hit that link saying "Google API Console".
Check under section "OAuth 2.0 client IDs". You need to click on the link "Web client (auto created by Google Service".
Copy/Paste your "Client ID" and "Client Secret" into your Firebase console under section "Web SDK Configuration (optional)"
Funny thing that you need to do this even though you may have only iOS app.
Re-Run your xCode project.
What fixed this for me is to create a new Firebase Project.
Go to https://console.firebase.google.com and choose CREATE NEW PROJECT. I tried everything I could think of in my old (upgraded) project and I just couldn't make it work. Also adding a new iOS app inside the old project wasn't enough.
I understand this is a bad option for a production app but as I'm still in the development phase wasn't a big deal for me.

Twitter #anywhere login having issues

I'm using the new twitter #anywhere api for logging in on the client using a popup. The api docs are here
https://dev.twitter.com/docs/anywhere/welcome#auth-events
Ive created a very simple example of their api, but after hitting "connect" on the popup, twitter just says "Something is technically wrong" as seen here in this screenshot
http://cl.ly/0A321R1Z2W1o3v0P0t0z
Here is my setup for doing this (note ive already created my app on twitter)
var api = "http://platform.twitter.com/anywhere.js?id={MY_API_KEY}&v=1";
$.getScript(api,function() {
twttr.anywhere(function (tw) {
console.log("tw",tw);
// bind auth compelte event
tw.bind("authComplete", function (e, user) {
console.log("tw auth complete",e,user);
});
// calling sign in triggeers the above event
tw.signIn();
});
});
So it opens the popup, lets me sign into twitter, and then when I hit connect, i get that odd error from twitter.
Any ideas what could be going wrong?
Thanks!
Update - I found this page of people having similar problems, but the solution they offered didn't change anything.
https://dev.twitter.com/discussions/1286
And it might be important to note the domain I'm using is http://changeup.dev its a local domain. I have it setup in my hosts file already.
SO, i Figured it out. You NEED to have a callback URL for your app, (on the developer page) even though it says you don't. The callback URL needs to match your authorized domain as well.
Then, in your app, the URL that the callback is calling, NEEDS to include the twitter api. THEN, and only THEN will the window automatically close and execute the authComplete callback.
I did this on the same page I was logging in from
if(location.hash && location.hash.indexOf("oauth_access_token") != -1) {

iOS: ShareKit >> Twitter Settings >> Callback URL --- What is it?

I'm trying to implement ShareKit in my app; in the SHKConfig.h file, in the section where the Twitter applications settings are required, there is a line where I'm supposed to set the Callback URL:
I have opened a Twitter application on Twitter and filled all the fields there, but I'm not clear regarding to what data should be inserted in the Callback URL field:
Can anyone explain?
The callback parameter you write in your application settings in Twitter is ignored, you can write anything, example: http://www.google.com (anything will do since it is ignored).
When you add a callback url in the #define, its value will be sent to twitter in the owner authorization step, and will override the value that you previously wrote in the Twitter website. Weird, I know. It's related to this security vulnerability.
The callback parameter is the URL Twitter is going to send the user after authentication. When running in websites instead applications, the URL callback is used to recover control of the OAuth flow.
On Applications, you can set it to a custom scheme like myapplication://twitter and then register the scheme myapplication in your app. This way, after authentication, the Twitter website running in UIWebView or Safari launches that URL, which iOS knows is assigned to your app, and that's how you recover control of the OAuth flow.
That's the theory, I don't know exactly how ShareKit works. It may be that it runs the authentication on a UIWebView and detects the activity of the user to recover control manually, which is another way to do it.
I'm using new version of ShareKit and in sources there is this comment about callback for twitter:
Callback URL' should match whatever you enter in
SHKTwitterCallbackUrl. The callback url doesn't have to be an actual
existing url. The user will never get to it because ShareKit
intercepts it before the user is redirected. It just needs to match.
I set in twitter settings callback url as http://somecallbackurl.com, set this same in sources and it works like a charm! :]. Hope this help.
You can use this
func application(_ application:UIApplication, open url: URL, options: [UIApplicationOpenURLOptionsKey: Any]) -> Bool {
print("called")
let directedByTWTR = Twitter.sharedInstance().application(application, open: url, options: options)
return directedByTWTR
}

Resources