AWS Cognito Update user login issue in iOS - ios

I am working on AWS Cognito login. It works fine in all cases such as SignUp, signIn, Forgot password etc. But it edit profile case, I am facing some technical problems. I edited my mobile number successfully.
In one of the case I provide wrong number and it throws an error like this,
[AWSJSONResponseSerializer responseObjectForResponse:originalRequest:currentRequest:data:error:] | Response body: {"__type":"InvalidParameterException","message":"Invalid phone number format.”}
I am using this set of code to update my profile,
[[user updateAttributes:#[attributes]] continueWithSuccessBlock:^id _Nullable(AWSTask<AWSCognitoIdentityUserUpdateAttributesResponse *> * _Nonnull task) {
//success
return nil;
}];
It provides only success responses. Failure responses are not coming inside this block. Can anyone help me how to get failure messages in this. I tried so many ways but still troubling to get proper solution. Any help will be appreciated. Thanks.

Related

MSGraphSDK user details API callback not responding back when user password changed in iOS

I tried to get the user details using MSGraph SDK in iOS using below API method. Iam successfully received the user details all the time. But when user charged their password or update their credentials, i received the oauthConnection Error: only in log. And i didn't receive any call back in the below API. Why it is not responding back when any kind of error occurred? Please help me. Thanks in advance.
[MSGraphClient setAuthenticationProvider:self.authProvider.authProvider];
self.graphClient = [MSGraphClient client];
[[[self.graphClient me]request]getWithCompletion:^(MSGraphUser *response, NSError *error) {
if(!error){
// Im able to get back here
}
else{
//Im not received any call back here when user changed their password or any error occurred.
[self.authProvider disconnect];
}
}];`
I am kinda new to MS Graph, so I might be missing something, but your graphClient declaration seems a little bit poor to me.
Try to download this sample: https://github.com/Azure-Samples/active-directory-dotnetcore-daemon-v2
And check it's declaration of graphClient.
You might be missing the part which refreshes the token?

Able to POST direct messages using Twitter's REST API, but trying to GET returns a 401 error

I am trying to get direct messages working in my app. I'm able to POST DMs just fine, but when I try to GET them from the endpoint https://api.twitter.com/1.1/direct_messages.json it returns a 401 - Unauthorized. I don't really understand how I can be authorized to send DMs but not get ones sent to me.
Here's how I'm authenticating initially:
if Twitter.sharedInstance().sessionStore.session() == nil {
Twitter.sharedInstance().logInWithCompletion { session, error in
if (session != nil) {
// successfully logged in, call loading functions
} else {
print("error: \(error!.localizedDescription)")
}
}
} else {
// already logged in, call loading functions
}
Every time I make a request using the REST API, it begins with
if let userID = Twitter.sharedInstance().sessionStore.session()?.userID {
let client = TWTRAPIClient(userID: userID)
The client is initialised the same way in both the POST and GET requests for DMs, yet the GET request fails.
As far as permissions go, I've checked that it has read/write/DM access according to Twitter, and successful requests return "x-access-level" = "read-write-directmessages";, so I think it's set properly.
I was concerned at one point that I might not be authenticating properly, since Twitter's documentation goes through the 3 step process for O-Auth and all I'm doing is telling the Twitter singleton to just log in... but I rationalised that away by assuming that those steps are all carried out in the logInWithCompletion function. And besides, if I wasn't authenticated properly I surely wouldn't be able to send DMs, right?
Any ideas on how I can fix this? I'm quite new so it may be something nice and simple! I've looked through some other questions, but they all seem to code the requests in full rather than using built-in methods like these - or have I got it all wrong?
Yeah, it was a stupid problem - I left the parameters blank since they are all marked as 'optional' - as in, a dictionary of ["" : ""]. I just set the paramaters in the request to nil, and now it works.

Parse error codes 209 and -34018

I have spent several hours learning user management on Parse, thinking it would be easy considering it's been an established service for so long.
There is poor documentation around 'automatic user' and sessions.
I am trying to build an App that allows the user to exist anonymously (using [PFUser enableAutomaticUser]), before they decide to sign up.
Registration Steps:
Gather user details from the UI
Log out current automatic user and wait for success
Upon success create a user object using [PFUser user] and assign values
Call signUpInBackgroundWithBlock on the new user instance
I sometimes get the following errors (yes, only sometimes), when doing the above.
[Error]: PFKeychainStore failed to get object for key 'currentUser', with error: -34018
[Error]: invalid session token (Code: 209, Version: 1.7.0)
I also end up with a dirty database, because I don't know how to delete the automatic user that was previously created. I tried keeping the object id of the old user around and using deleteEventually but that didn't work?
Any advice on how you would go about achieving this would be great.
Take a look at this issue with parse on iOS: https://github.com/ParsePlatform/Parse-SDK-iOS-OSX/issues/437.
I believe this was an issue in iOS and is now fixed
Actually, this is a bug of keychain, you can search it at github.
Github 34018 issues
A few months ago, some apple's staff came our company to give us a course, after course,we asked this question, they also did't give us a solution
I've solved this problem by using the following:
PFUser *user = [PFUser currentUser];
[user refreshInBackgroundWithBlock:^(PFObject *object, NSError *error) {
if (!error) {
NSLog(#"Succesfully refreshed the current user.");
} else {
NSLog(#"Failed to refresh the current user with error %#", error);
}
}];
It seems that [PFUser currentUser] returns an invalid session token which is causing the 209 and -34018 errors. This is only an issue when the current user is an anonymous user.

AWS DynamoDB iOS SDK silently failing but always returning success status

I've created an iOS application following AWS Mobile SDK examples using AWSiOSSDKv2.
I've successfully been able to connect with an unauthorized Cognito account to DynamoDB and write to the table. I log into AWS, check the table and see my records are there.
AWSDynamoDBObjectMapper *dynamoDBObjectMapper = [AWSDynamoDBObjectMapper defaultDynamoDBObjectMapper];
[[dynamoDBObjectMapper save:tableRow] continueWithSuccessBlock:^id(BFTask *task) {
if (!task.error) {
NSLog(#"Successfully inserted the data into the table.");
} else {
NSLog(#"Failed to insert the data into the table.");
}
return nil;
}];
However, now I want to test what will happen in a failure. I deliberately try to cause an error by changing the dynamoDBTableName to something that does not exist. Unfortunately, my code always returns success even tho it was not.
I found in another thread someone recommending putting logging to verbose which I did.
[AWSLogger defaultLogger].logLevel = AWSLogLevelVerbose;
And in the console, I do see that AWSLogger displays an error:
[{"__type":"com.amazon.coral.service#AccessDeniedException","Message":"User:
arn:aws:sts::xxxxxx:assumed-role/Cognito_xxxxxxxxUnauth_DefaultRole/iOS-Provider
is not authorized to perform: dynamodb:PutItem on resource:
arn:aws:dynamodb:us-east-1:xxxxxxxxxxxxx:table/xxxxxxxx"}]
However, In my code above, it always writes "Successfully inserted the data into the table.".
I've even tried modifying AWS Mobile Examples and can reproduce the same bug. I've also tried installing the POD and manually adding the AWSiOSSDKv2 framework to my project, neither fix the issue.
Has anyone run into this issue and does anyone know how to resolve? I'm trying to create an unauthorized user who only has write access to the dynamodb table.
Thanks
This is a known issue of the SDK, and the fix is on its way.
In the meanwhile, if you are using CocoaPods, adding the following lines to AWSDynamoDBObjectMapper.m L154 should fix it:
if (task.error) {
return task;
}

iOS OneDrive (skydrive) app displays permissions dialog every time it runs

I'm developing an iOS app that gives users access to their OneDrive/SkyDrive and I've run into a very annoying issue:
The very first time a user links the app to their OneDrive, everything goes as expected:
They have to enter a user id and password
Then they have to agree to let the app access their info
Then they get to browse their OneDrive
That's all good.
But, if the app closes, and you try to access the OneDrive again, rather than skipping straight to #3, and being able to access the OneDrive, they are stopped at step #2 (step 1 is skipped, as expected) and they have to agree again to let the app access their info.
The code is taken directly from the iOS examples in the online documentation (with some slight modification based on samples found here on Stack Overflow), but, here it is for inspection:
- (void) onedriveInitWithDelegate:(id)theDelegate {
self.onedriveClient = [[LiveConnectClient alloc] initWithClientId:MY_CLIENT_ID
delegate:theDelegate
userState:#"initialize"];
}
And then, theDelegate implements this:
- (void)authCompleted:(LiveConnectSessionStatus) status
session:(LiveConnectSession *) session
userState:(id) userState {
NSLog(#"Status: %u", status);
if ([userState isEqual:#"initialize"]) {
NSLog( #"authCompleted - Initialized.");
if (session == nil) {
[self.onedriveClient login:self
scopes:[NSArray arrayWithObjects:#"wl.basic", #"wl.signin", #"wl.skydrive_update", nil]
delegate:self
userState:#"signin"];
}
}
if ([userState isEqual:#"signin"]) {
if (session != nil) {
NSLog( #"authCompleted - Signed in.");
}
}
}
I thought that perhaps the status value might give a clue and that maybe I could avoid the login call, but it's always zero/undefined when I get to authCompleted after calling initWithClientId. (And session is always nil.)
Is there a scope I'm missing? Is there a different call to make rather than a straight-up login call? Or is it more complicated than that? I've seen reference to "refresh tokens" related to OAuth2 login, but I've not been able to find any concrete examples of how they might be used in this situation.
Any help and/or insights greatly appreciated.
Diz
Well, it turns out that the answer is pretty simple here. I just needed to add the "wl.offline_access" scope to my list of scopes during the initial login operation. The docs didn't really imply this type of behavior for this scope, but, that did the trick for me.
With this new scope added, subsequent invocations of the app no longer bring up the "agree to give the app these permissions" dialog, and I can go straight to browsing the OneDrive.
(Credit where it's due: Stephane Cavin over at the microsoft forums gave me the tip I needed to work this out. Gory details are here:
http://social.msdn.microsoft.com/Forums/en-US/8c5c7a99-7e49-401d-8616-d568eea3cef1/ios-onedrive-skydrive-app-displays-permissions-dialog-every-time-it-runs?forum=onedriveapi )
Diz

Resources