I need your help about auth0 social login. I have following ios code
- (IBAction)linkedin:(id)sender {
A0Lock *lock = [MyApplication sharedInstance].lock;
A0APIClient *client = [lock apiClient];
A0APIClientAuthenticationSuccess success = ^(A0UserProfile *profile, A0Token *token) {
NSLog(#"We did it!. Logged in with Auth0.");
};
A0APIClientError failure = ^(NSError *error){
NSLog(#"Oops something went wrong: %#", error);
};
A0AuthParameters *params = [A0AuthParameters newDefaultParams];
params[A0ParameterConnection] = #"linkedin"; // Or your configured DB connection
[client authenticateWithSocialConnectionName:#"linkedin"credentials:#"token" parameters:nil success:success failure:failure];
My aim is simple, i try to create social login connection via using auth0. In the quickstart documentation of auth0 there is a sample which is using controller, and i also add custom connections.
- (IBAction)signUp:(id)sender {
A0Lock *lock = [[MyApplication sharedInstance] lock];
A0LockViewController *controller = [lock newLockViewController];
controller.connections=#[#"facebook", #"linkedin"];
controller.useWebView=YES;
controller.onAuthenticationBlock = ^(A0UserProfile *profile, A0Token *token) {
// Do something with token & profile. e.g.: save them.
// And dismiss the ViewController
[self dismissViewControllerAnimated:YES completion:nil];
};
[self presentViewController:controller animated:YES completion:nil];}}
But i cant use this because i need custom UI, i want to do this without controller. Can you please help me, what i m doing wrong in "authenticateWithSocialConnectionName" part. Thank you very much.
Related
I have had facebook sharing working fine in my ios app for a year and have upgraded (aka totally rewritten) to use the latest api (4.7.x) and now sharing doesnt work at all. I check that I have publish_actions permission (which I do prior to this method being called, I have 'expicitly shared' checked in open graph settings, action types, capabilities. I am validating the content (I dont get an error) and have a delegate, none of its methods get called.
-(void)shareWithFacebook:(NSString *)message
{
if ([[FBSDKAccessToken currentAccessToken] hasGranted:#"publish_actions"])
{
NIDINFO(#"Facebook sharing has publish_actions permission");
}
else
{
FBSDKLoginManager *loginManager = [[FBSDKLoginManager alloc] init];
[loginManager logInWithPublishPermissions:#[#"publish_actions"]
handler:^(FBSDKLoginManagerLoginResult *result, NSError *error)
{
NIDERROR(#"Facebook sharing getting publish_actions permission failed: %#", error);
}
];
}
NSMutableDictionary *properties = [NSMutableDictionary dictionaryWithDictionary: #{
#"og:type": #"article",
#"og:title": #"Bloc",
#"og:description": message,
#"og:url": #"http://getonbloc.com/download"
}];
FBSDKShareOpenGraphObject *object = [FBSDKShareOpenGraphObject objectWithProperties:properties];
// Create the action
FBSDKShareOpenGraphAction *action = [FBSDKShareOpenGraphAction actionWithType:#"mynamespace:Share" object:object key:#"article"];
[action setString:#"true" forKey:#"fb:explicitly_shared"];
// Create the content
FBSDKShareOpenGraphContent *content = [[FBSDKShareOpenGraphContent alloc] init];
content.action = action;
content.previewPropertyName = #"article";
// Share the content
FBSDKShareAPI *shareAPI = [[FBSDKShareAPI alloc] init];
shareAPI.shareContent = content;
shareAPI.delegate = self;
NSError *error;
if([shareAPI validateWithError:&error] == NO)
{
NIDERROR(#"Facebook sharing content failed: %#", error);
}
[shareAPI share];
}
#pragma mark - FBSDKSharingDelegate
- (void) sharer:(id<FBSDKSharing>)sharer didCompleteWithResults:(NSDictionary *)results
{
NIDINFO(#"Facebook sharing completed: %#", results);
}
- (void) sharer:(id<FBSDKSharing>)sharer didFailWithError:(NSError *)error
{
NIDERROR(#"Facebook sharing failed: %#", error);
}
- (void) sharerDidCancel:(id<FBSDKSharing>)sharer
{
NIDINFO(#"Facebook sharing cancelled.");
}
I have login working and can get photos fine. I don't get any feedback at all from the facebook api, nothing gets posted. Am I doing something particularly stupid here?
Just a possibility, but I find that Facebook integration has become inconvenient because I find that every time I check the current token for granted permission through hasGranted:, it almost always fail even though I gained permission a few minutes ago, or from a previous app launch.
It seems that in your code, if no permission is granted, you try to login and get the permission again. But when that block returns, regardless whether the actual permission is granted or not, you throw an error. Instead, you should continue with sharing if it is successful.
I'm receiving this crash in my iOS app using Salesforce after user taps on 'Deny' button in app permission screen after login.
I have referred sample app given by SF for & it’s displaying an error alert for same scenario.
Don’t know what I’m missing
Error:
Error Domain=com.salesforce.OAuth.ErrorDomain Code=669 "end-user denied authorization" UserInfo=0x1d8ab880 {NSLocalizedDescription=end-user denied authorization, error=access_denied}
-[SFOAuthCoordinator setAuthInfo:]: message sent to deallocated instance 0x189b1370
Below is the code I’m using:
Appdelegate:
init method
[SFLogger setLogLevel:SFLogLevelDebug];
[SalesforceSDKManager sharedManager].connectedAppId = RemoteAccessConsumerKey;
[SalesforceSDKManager sharedManager].connectedAppCallbackUri = OAuthRedirectURI;
[SalesforceSDKManager sharedManager].authScopes = #[ #"web", #"api" ];
__weak AppDelegate *weakSelf = self;
[SalesforceSDKManager sharedManager].postLaunchAction = ^(SFSDKLaunchAction launchActionList) {
[weakSelf setupRootViewController];
};
[SalesforceSDKManager sharedManager].launchErrorAction = ^(NSError *error, SFSDKLaunchAction launchActionList) {
[weakSelf initializeAppViewState];
[[SalesforceSDKManager sharedManager] launch];
};
[SalesforceSDKManager sharedManager].postLogoutAction = ^{
[weakSelf handleSdkManagerLogout];
};
[SalesforceSDKManager sharedManager].switchUserAction = ^(SFUserAccount *fromUser, SFUserAccount *toUser) {
[weakSelf handleUserSwitch:fromUser toUser:toUser];
didFinishLaunchingWithOptions:
[[SalesforceSDKManager sharedManager] launch];
ViewController: (deferred login)
[[SFAuthenticationManager sharedManager] loginWithCompletion:^(SFOAuthInfo *sfOAuthInfo) {
NSLog(#"authentication successful!!!");
}
failure:^(SFOAuthInfo *sfOAuthInfo, NSError *error) {
NSLog(#"Authentication failure!!!");
}];
As an incident of a user taking some action in my app, I want to post an image to Facebook on their behalf. Let's assume the user has already granted me publish_actions permission in class LoginVC (one time permission is used for ad infinitum posting in the future). Then at some in the future, in ActionVC, I want to publish a photo to Facebook. How do I do that? Here is the method I need to implement:
- (void)publishPhoto:(UIImage *)image
{
//what goes in here?
}
So far I have been looking at the samples from Facebook. The closest I come is the following, but it seems to be using a Dialog. But I don't want the user to "know" that the photo is being posted. They already granted the permission and I want the posting to happen without their knowledge as it were. So some other action has triggered the call to publish...
For reference, the code from the Facebook sample looks like this
- (void)publishPhoto:(UIImage *)image
{
BOOL canPresent = [FBDialogs canPresentShareDialogWithPhotos];
NSLog(#"canPresent: %d", canPresent);
FBPhotoParams *params = [[FBPhotoParams alloc] init];
params.photos = #[image];
BOOL isSuccessful = NO;
if (canPresent) {
FBAppCall *appCall = [FBDialogs presentShareDialogWithPhotoParams:params
clientState:nil
handler:^(FBAppCall *call, NSDictionary *results, NSError *error) {
if (error) {
NSLog(#"Error: %#", error.description);
} else {
NSLog(#"Success!");
}
}];
isSuccessful = (appCall != nil);
}
if (!isSuccessful) {
[self performPublishAction:^{
FBRequestConnection *connection = [[FBRequestConnection alloc] init];
connection.errorBehavior = FBRequestConnectionErrorBehaviorReconnectSession
| FBRequestConnectionErrorBehaviorAlertUser
| FBRequestConnectionErrorBehaviorRetry;
[connection addRequest:[FBRequest requestForUploadPhoto:image]
completionHandler:^(FBRequestConnection *innerConnection, id result, NSError *error) {
[self showAlert:#"Photo Post" result:result error:error];
if (FBSession.activeSession.isOpen) {
self.buttonPostPhoto.enabled = YES;
}
}];
[connection start];
self.buttonPostPhoto.enabled = NO;
}];
}
}
Sorry if this question seems too easy, but I am a newbie to Facebook SDK integration
Generally you definitely want the user to be aware that something is being posted on their behalf, but to answer your question, if they've already granted you publish permissions, then you can use the code in the second "if" statement that you posted above, where it calls FBRequest requestForUploadPhoto:
I have an application that i need to integrate with twitter login, for logging in via their twitter account. In the application we also have Twitter sharing option. Here i want to implement functionality to choose their account in which account they want to share the tweet. If user is logged in for only one account, then there should be provision to login to another account without logging out of existing logged-in account.
Well, this really compounds about 5 different topics in to one, and we can't write your entire app for you, but here are some helpful pointers.
When it comes to twitter, I use the STTwitter API (https://github.com/nst/STTwitter). What this does is takes all the twitter code, and dumbs it down for us less objective-c inclined programmers. The "README" file contains more information about what you'd be needing. You can find the developer tutorial at http://www.veasoftware.com/tutorials/2014/6/17/xcode-5-tutorial-ios-7-app-only-authentication-twitter-api-version-11. This also allows you to download the project to test, and copy and paste code from.
Youtube and Google are also great sources to find information. Right now your request is quite broad and encompases quite a few different aspects of twitter integration, work on them one at a time from the ground up.
====>Download Third Party Class FSHTwitterEngine.
{
[[FHSTwitterEngine sharedEngine]permanentlySetConsumerKey:#"6XITOIDiXNajx7TQMKOh8qDxj" andSecret:#"w4F44ATueFsarNjGQ9WDdEudJCBJ8P0o5zeNON5bP9hIKhGls6"];
[[FHSTwitterEngine sharedEngine]setDelegate:self];
[[FHSTwitterEngine sharedEngine]loadAccessToken];
UIViewController *loginController = [[FHSTwitterEngine sharedEngine]loginControllerWithCompletionHandler:^(BOOL success) {
NSLog(success?#"L0L success":#"O noes!!! Loggen faylur!!!");
[self performSelector:#selector(TwitterPostMessage) withObject:nil afterDelay:1.0];
}];
[self presentViewController:loginController animated:YES completion:nil];
}
-(void)TwitterPostMessage
{
UIImage *aimg = [UIImage imageNamed:#"mark"];
// [[FHSTwitterEngine sharedEngine]postTweet:#"Hepp adsfihdf sdfhihdsfh" withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
#autoreleasepool {
//NSString *tweet = [alertView textFieldAtIndex:0].text;
// id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Post of image"];
id returned = [[FHSTwitterEngine sharedEngine]postTweet:#"Hi Successfully Post Twitter..." withImageData:UIImagePNGRepresentation(aimg)];
[UIApplication sharedApplication].networkActivityIndicatorVisible = NO;
NSString *title = nil;
NSString *message = nil;
if ([returned isKindOfClass:[NSError class]])
{
NSError *error = (NSError *)returned;
title = [NSString stringWithFormat:#"Error %d",error.code];
message = error.localizedDescription;
} else {
NSLog(#"%#",returned);
title = #"Tweet Posted";
message = #"Post of image";
}
dispatch_sync(dispatch_get_main_queue(), ^{
#autoreleasepool {
UIAlertView *av = [[UIAlertView alloc]initWithTitle:title message:message delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[av show];
}
});
}
});
}
When logging a user into my application I need to pull a user object down from the server using only the username. This returns the userId (among other things) that I need in order to make other API calls. From that point I'll make a couple other HTTP calls using the userId. How can I make a synchronous call to completely pull down the user object before sending the other calls?
I've setup my object mapping in my app delegate class, which works perfectly, and am using this code to pull the user object down from the server:
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[#"/api/users/" stringByAppendingString:[_userNameField text]] delegate:self];
This is what I've tried... as suggested here: Making synchronous calls with RestKit
RKObjectLoader* loader = [[RKObjectManager sharedManager] objectLoaderForObject:currentUser method:RKRequestMethodPUT delegate:nil];
RKResponse* response = [loader sendSynchronously];
However this code (1) uses the deprecated method objectLoaderForObject and (2) crashes saying 'Unable to find a routable path for object of type '(null)' for HTTP Method 'POST''.
Putting aside the question of whether this is the ideal design for an iPhone application, I was able to accomplish what I was hoping using blocks.
[[RKObjectManager sharedManager] loadObjectsAtResourcePath:[#"/api/users/" stringByAppendingString:[_userNameField text]] usingBlock:^(RKObjectLoader* loader) {
loader.onDidLoadResponse = ^(RKResponse *response) {
NSLog(#"Response: \n%#", [response bodyAsString]);
};
loader.onDidLoadObjects = ^(NSArray *objects) {
APIUser *apiUser = [objects objectAtIndex:0];
NSLog(#"user_id is %i", apiUser.user_id);
};
loader.onDidFailWithError = ^(NSError *error) {
UIAlertView *badLoginAlert = [[UIAlertView alloc]initWithTitle:NSLocalizedString(#"LOGIN_FAILED", nil)
message:NSLocalizedString(#"BAD PASSWORD OR USERNAME", nil)
delegate:self
cancelButtonTitle:NSLocalizedString(#"OK", nil)
otherButtonTitles:nil];
[badLoginAlert show];
};
}];
Hope this helps someone.