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.
Related
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
I have working Swift code that opens an SFSafariViewController at the following URL:
https://api.imgur.com/oauth2/authorize?client_id=\(CLIENT_ID)&response_type=token&state=myState
to retreive a user token from Imgur.
With this, the user can upload photos to his personal account.As this is going to be a commercial App, I registered an App on Mashape and changed my URLs in the code to use that endpoint:
like written here
My problem is the authentication. Anonymous uploads work perfectly as I put the X-Mashape-Key in the request header correctly.
But the presented Safari window is just initialized with a URL:
let url = NSURL(string: "https://imgur-apiv3.p.mashape.com/oauth2/authorize?client_id=\(CLIENT_ID)&response_type=token&state=myState")
svc = SFSafariViewController(url: url as! URL)
svc!.delegate = self
self.present(svc!, animated: true, completion: nil)
so I don't get where to tell it the Mashape key or if it's not required, what is then.
Do I maybe need to change the CLIENT_ID? Currently it's still the one I had gotten from Imgur and Mashape doesn't seem to have sth like this. There's only the API keys.
Any help is appreciated, thank you in advance!
EDIT:
I changed the authentication URL back to the original one from Imgur and using the CLIENT_ID from Imgur.
Now the images are uploaded to the user's account while showing in my Mashape quotas, which indicates everything is as expected.
I'm not sure if this is perfectly correct as the abovementioned Link tells to change the API endpoints in general to the new one.
On the other hand, authorization is not really something using an API endpoint, rather it's a webpage with a callback, so ... Not sure! That's why I ask :)
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.
I read the below link and now I understood that I need to make an api call to fetch the contacts. As I am new to Swift3 could someone guide me how to do this. I read somewhere that Almofire and Swifty json would help and I also read GData also will help. I am little confused. Please guide me.
Google Contacts API
You might want to try Google Sign-In for iOS, get users into your apps quickly and securely, using a registration system they already use and trust—their Google account. This Google Sign-in videos - series #1, series #2 and series #3 will help you understand the implementation of Google SignIn in iOS, how do you use Google Sign in on iOS with another service like Google Drive? and more.
Here are some tutorials and reference that can help:
Integrate Google Signin SDK In iOS Application Using Swift
How to Integrate Google Sign In into Your iOS Apps
Requesting additional scopes after sign-in
Invite friends from Gmail (This tutorial use a gmail contact scope rather than the google plus contacts) PS. not an iOS tutorial
Lastly here are some related SO question for refrence - How to fetch gmail Contacts in iOS application using google contacts api? and Get Google contacts using API on iOS
Hope this helps.
I was actually stuck on this too and couldn't find a solution but I ended up figuring it out. You first need to authenticate with Google Sign In and then pass the accessToken into this endpoint:
let urlString = ("https://www.google.com/m8/feeds/contacts/default/full?alt=json&max-results=5000&access_token=\(GIDSignIn.sharedInstance().currentUser.authentication.accessToken!)")
guard let url = URL(string: urlString) else { return }
URLSession.shared.dataTask(with: url, completionHandler: {
(data, response, error) in
if(error != nil){
print("error")
}else{
do{
let json = try JSONSerialization.jsonObject(with: data!, options:[]) as! [String : AnyObject]
//parse JSON
}catch let error as NSError{
print(error)
}
}
}).resume()
I'm currently working on an iOS app which will (if I can figure out this problem) use Azure as backend. The user is supposed to login with their iOS account which they already setup on their iOS device. I than use reverse authentication (https://dev.twitter.com/docs/ios/using-reverse-auth) to get the user's access token and I would like to use said access token to login the user.
I tried using (Swift snippet)
let tokenDictionary = ["access_token": "<token-I-got>"];
client.loginWithProvider("twitter", token: tokenDictionary.bridgeToObjectiveC(), completion: {(user: MSUser!, error: NSError?) in
if let user = user? {
print(user.userId)
} else if let error = error? {
print(error)
}
})
but the only thing the API returns is:
POST of Twitter token is not supported.
Any ideas how I could get this to work or do I have to switch away from Azure to something different? (And using the webview for login is not an option, as we have this nice already accounts on iOS already setup with the credentials).
Thanks for helping.
This feature is not currently supported by Azure Mobile Services. You can upvote the feature request here.