Firebase Google SignIn failed - "Audience Mismatch" - swift

I have implemented Google sign in via Firebase and followed proper documentation: https://firebase.google.com/docs/auth/ios/firebaseui
I am using,
- FirebaseUI/Auth (8.5.1):
- Firebase/Auth (~> 6.0)
- GoogleUtilities/UserDefaults
- FirebaseUI/Google (8.5.1):
- FirebaseUI/Auth
- GoogleSignIn (~> 5.0)
COCOAPODS: 1.9.3
XCode - 12
So, my Appdelegate.swift would contain following code in didFinishLaunchingWithOptions...
FirebaseApp.configure()
And presenting SignIn UI when user presses a special button on Login view controller using below code,
if let authController = authUI?.authViewController() {
self.authController = authController
self.present(authController, animated: true, completion: nil)
}
LoginViewController.swift would have following code into viewDidload()
authUI?.delegate = self
let providers: [FUIAuthProvider] = [
FUIGoogleAuth()
]
authUI?.providers = providers
where authUI is declared as property for LoginViewController => let authUI = FUIAuth.defaultAuthUI()
I have only added Google SignIn for now so only one provider added here.
Now when my SignIn Auth UI is presented, Google SignIn button is shown and I am able to log into my Google account but when didSignInWith authDataResult is executed from FUIAuthDelegate, I get to know I am receiving an error post successful Google Account Login.
Error Domain=FUIAuthErrorDomain Code=2 "(null)" UserInfo={FUIAuthErrorUserInfoProviderIDKey=google.com, NSUnderlyingError=0x600000a08720 {Error Domain=org.openid.appauth.general Code=-15 "Audience mismatch" UserInfo={NSLocalizedDescription=Audience mismatch}}}
Is there anything I am missing?
I have already setup URL schema into info.plist and not getting any clue on how this kind of error is being generated.
Further as an update to #frank-van-puffelen,
I have confirmed proper info.plist is added or not.
My Info.Plist
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CLIENT_ID</key>
<string>847792004435-gdisqis038je5q8rr1on4ti7df09nvht.apps.googleusercontent.com</string>
<key>REVERSED_CLIENT_ID</key>
<string>com.googleusercontent.apps.847792004435-gdisqis038je5q8rr1on4ti7df09nvht</string>
<key>API_KEY</key>
<string>AIzaSyDRrYM2h1wOEdKHZtOM-M904oBwrXnaO3E</string>
<key>GCM_SENDER_ID</key>
<string>847792004435</string>
<key>PLIST_VERSION</key>
<string>1</string>
<key>BUNDLE_ID</key>
<string>com.Speare.StashAlpha</string>
<key>PROJECT_ID</key>
<string>stash-demo-11379</string>
<key>STORAGE_BUCKET</key>
<string>stash-demo-11379.appspot.com</string>
<key>IS_ADS_ENABLED</key>
<false></false>
<key>IS_ANALYTICS_ENABLED</key>
<false></false>
<key>IS_APPINVITE_ENABLED</key>
<true></true>
<key>IS_GCM_ENABLED</key>
<true></true>
<key>IS_SIGNIN_ENABLED</key>
<true></true>
<key>GOOGLE_APP_ID</key>
<string>1:847792004435:ios:867e5fb8113b83b48f55a6</string>
<key>DATABASE_URL</key>
<string>https://stash-demo-11379.firebaseio.com</string>
</dict>
</plist>
Screenshot of project which is targeted for login,
We can clearly check here Project ID matches in info.plist as well as on Sign In screen.
Now in Firebase console, if we check, project ID matches and below is info.plist download button from where I can take latest info.plist.
Let me know if there is anything we can confirm info.plist does not match with target project.

This error message usually means that you're trying to sign in to a different project than what the token was minted for. So you might want to check if you have the info.plist for the correct project, and that you're set up you OAuth sign in against that same project.

Related

Can't request calendar event access (via EKEventStore) in Swift app for macOS

(I've never used Swift or Xcode before so this is probably a stupid question)
To isolate the issue, I created a totally empty "App" in Xcode 11, and put this into the AppDelegate.swift:
import Cocoa
import EventKit
#NSApplicationMain
class AppDelegate: NSObject, NSApplicationDelegate {
private let eventStore = EKEventStore()
func applicationDidFinishLaunching(_ aNotification: Notification) {
eventStore.requestAccess(to: .event) { granted, error in
if granted {
print("GOOD: Access granted")
} else {
print("BAD: Access denied")
}
}
}
}
When I run the app (via cmd+R), I immediately see that it denied access, without ever giving me the chance to approve access:
Metal API Validation Enabled
BAD: Access denied
What am I doing wrong? How can I get it to allow me to approve access to calendar events?
Note that I noticed that the docs say:
To access the user’s Calendar data, all sandboxed macOS apps must include the com.apple.security.personal-information key.
So I made that change like so in App_Name.entitlements but it didn't help:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>com.apple.security.personal-information</key>
<true/>
<key>com.apple.security.app-sandbox</key>
<true/>
<key>com.apple.security.files.user-selected.read-only</key>
<true/>
</dict>
</plist>
Fixed. 2 things I had wrong:
com.apple.security.personal-information in the entitlements file was incorrect. Just typing "Calendar" autocompletes to the correct one.
In the Info.plist file, I needed "Privacy - Calendars Usage Description" to have a value. I found that here: https://forums.developer.apple.com/thread/110825

Apple Script fails when run from within a macOS Swift-based application

SOLUTION:
I needed to do two things to solve my problem:
1) Add the following to my app's entitlements file:
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.Mail</string>
</array>
2) Add the following to my app's plist:
<key>NSAppleEventsUsageDescription</key>
<string>Please allow "your message here"</string>
This works on Mojave 10.14 (18A389)
I have a basic Swift-based macOS app. I'd like to use Apple Script to determine the number of unread email messages in Mail.app. I created a small Apple Script and tested it in Script Debugger (it works fine).
When I run the same script from within my app though it fails stating that the Mail application isn't running (even though it is):
let unreadEmailsScript = """
tell application "Mail"
get unread count of inbox
end tell
"""
if let scriptObject = NSAppleScript(source: unreadEmailsScript) {
var errorDict: NSDictionary? = nil
scriptObject.executeAndReturnError(&errorDict)
if let error = errorDict {
print(error)
}
}
Output:
{
NSAppleScriptErrorAppName = Mail;
NSAppleScriptErrorBriefMessage = "Application isn't running.";
NSAppleScriptErrorMessage = "Mail got an error: Application isn't running.";
NSAppleScriptErrorNumber = "-600";
NSAppleScriptErrorRange = "NSRange: {33, 12}";
}
I haven't executed Apple Script from within an app before. Is this error due to a permissions problem?
Yes, it's a permission problem.
Your app is sandboxed and you have to specify appropriate entitlements. Add this in the entitlements file of your app:
<key>com.apple.security.temporary-exception.apple-events</key>
<array>
<string>com.apple.Mail</string>
</array>

Twitter Call back URL

I am working with twitter SDK to integrate with in ios app.When i follow all the step and create the customer key and put it in my app.When I run the app it show
"[TwitterKit] did encounter error with message
"Error obtaining user auth token.": Error Domain=TWTRLogInErrorDomain
Code=-1 "Callback URL not approved for this client application.
Approved callback URLs can be adjusted in your application
settings" UserInfo={NSLocalizedDescription=Callback URL
not approved for this client application. Approved callback URLs can
be adjusted in your application settings"
How to resolve this?
I had the same problem and the TwitterKit documentation is not accurate or Twitter has changed their policies. In any case, on the Twitter Apps site, the callback URL has to be set very specifically. The callback URL should be in the format:
twitterkit-{consumer/api key}://
For example:
twitterkit-128238aKjqlp123AKdasdf://
Also, this needs to be registered in your Info.plist exactly the same:
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>twitterkit-128238aKjqlp123AKdasdf</string>
</array>
</dict>
More documentation is listed here: https://developer.twitter.com/en/docs/basics/callback_url.html
I just added on callback url field twitterkit-<api/consumer Key>://.
If you have an apiKey like abc you should add twitterkit-abc://. This work for iOS, for Android just add twittersdk://.
To Fix this issue do as below:
[Mandatory]
Add CallbackURL into the dashboard as below format:
For iOS:
twitterkit-CONSUMERKEY://
For Android:
twittersdk://
Help Link:
https://twittercommunity.com/t/ios-twitter-login-error-code-415/107775
[ Note: Please replace your consumer key in place of words "CONSUMERKEY" in above format]
My solution: I hope it's useful.
Go to https://apps.twitter.com
Then in the "Settings" tab of your app.
Fill the "Callback URLs" form.
According to this documentation i guess you just have to enter a valid URL :
https://github.com/twitter/twitter-kit-ios/wiki/Installation
NOTE: Although the callback URL will not be requested by Twitter Kit in your app, it must be set to a valid URL for the app to work with the SDK.
Hey everyone here is a simple fix that worked for me.
Go to: https://apps.twitter.com
Go into the settings tab.
Under Terms of Service URL uncheck the box that says:
"Unable Callback Locking"
Now test your app.
Finally I found the solution for my case. Hope it'll help someone else
Put this in URL Callback field.
twittersdk://
Refer: https://github.com/twitter/twitter-kit-android/issues/135

Facebook Account Kit SDK gives invalid OAuth 2.0 error

I have integrated Account kit sdk in to my project.
I created the application on facebook development dashboard, enabled Account Kit on it. Got app-id and client access token.
I added it into info.plist file. I am getting this error:
[AccountKit][Error]: Invalid OAuth 2.0 Access Token
2016-05-31 02:41:32.191 Chat[2919:563260] [AccountKit][Error]:
Persisting App Events due to error:
Error Domain=com.facebook.accountkit:Error Code=200 "(null)"
UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token., NSUnderlyingError=0x147596a30
{Error Domain=com.facebook.accountkit:ServerError Code=190 "(null)" UserInfo={com.facebook.accountkit:ErrorDeveloperMessageKey=Invalid OAuth access token.}}}
Please need help. Thanks
Make sure you have the correct settings in info.plist.
I had a similar problem and in my case it was missing a key FacebookAppID
<key>FacebookAppID</key>
<string>{your-app-id}</string>
<key>AccountKitClientToken</key>
<string>{your-account-kit-client-token}</string>
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLSchemes</key>
<array>
<string>ak{your-app-id}</string>
</array>
</dict>
</array>
Make sure that initialization response type of AKFAccountKit matches with your application dashboard configuration.
It can be:
accountKit = [[AKFAccountKit alloc] initWithResponseType:AKFResponseTypeAccessToken];
or
accountKit = [[AKFAccountKit alloc]initWithResponseType:AKFResponseTypeAuthorizationCode];
This might be an issue with your configuration. You can file a bug report with Facebook here including your token information: https://developers.facebook.com/bugs/
I got this error when I had copied the wrong AccountKitClientToken into the Info.plist. Got the right one in there and everything is working now!
You can add your client token using AKFSettings.setClientToken("MY TOKEN") and make sure to import AccountKit at the top of the file where you call this.

"Cannot Open Page" Error when doing Facebook single sign on in Appcelerator Titanium

I have setup a view in my appcelerator titanium app to be nearly identical to the one in the kitchen sink demo for facebook login. I want to use single sign on for IOS:
//LoginView Component Constructor
function LoginView() {
//create object instance, a parasitic subclass of Observable
var self = Ti.UI.createView();
// APP ID BELOW IS CHANGED FOR DEMO PURPOSES
Titanium.Facebook.appid = "111111111111111";
Titanium.Facebook.permissions = ['email', 'publish_actions'];
// ENABLE SINGLE SIGN ON
Titanium.Facebook.forceDialogAuth = false;
self.add(Titanium.Facebook.createLoginButton({
style:Ti.Facebook.BUTTON_STYLE_WIDE,
bottom:30
}));
return self;
}
module.exports = LoginView;
When clicking the login button, it successfully opens the facebook login dialog in safari and I login. Then when it tries to take me back to the app, I get the error:
Cannot Open the Page Safari cannot open the page because the address
is invalid
Very similar code works correctly in the kitchen sink app, and also disabling single sign on makes logging in through facebook work correctly in my app.
All I have for the settings in the facebook app is:
Facebook Login - Enabled
Am I missing anything from the settings?
Figured it out:
In my facebook app settings (on developers.facebook.com), I set the bundle Id to the same id as my app in Appcelerator.
Based on the q & a:
Copied Info.plist from build/iphone/ into the root of the application.
Added the xml element fb111111111111111 below under app to Info.plist:
<key>CFBundleURLTypes</key>
<array>
<dict>
<key>CFBundleURLName</key>
<string>com.mycompany.app</string>
<key>CFBundleURLSchemes</key>
<array>
<string>app</string>
<string>fb111111111111111</string>
</array>
</dict>
</array>
Where 111111111111111 is changed to the id of the app