I'm trying to use oauth2 to get data from 23 and me, but keep getting "bad request" codes. This is my first time working with OAuth2 and I'm not sure what I'm doing wrong.
When I use AFOAuth2Client, I get error code 400:
AFOAuth2Client* oauthClient = [AFOAuth2Client clientWithBaseURL:[NSURL URLWithString:#"https://api.23andme.com/"] clientID:clientIDString secret:secretString];
[oauthClient authenticateUsingOAuthWithPath:#"/token/"
code:#"zzz"
redirectURI:#"myapp://callback/oauth"
scope:#"analyses"
success:^(AFOAuthCredential *credential)
{
NSLog(#"I have a token! %#", credential.accessToken);
[AFOAuthCredential storeCredential:credential withIdentifier:oauthClient.serviceProviderIdentifier];
}
failure:^(NSError *error) {
NSLog(#"Error: %#", error);
}];
The error block is hit with this message:
Error: Error Domain=com.alamofire.networking.error Code=-1011 "Expected status code in (200-299), got 400" UserInfo=0x1fda4f80 {NSErrorFailingURLKey=https://api.23andme.com/token/, NSLocalizedDescription=Expected status code in (200-299), got 400}
When I try GTMOauth2Sample, I get invalid_client error after the authorization screen dismisses.
What am I doing wrong?
You can try to use this client from 23andme https://github.com/23andMe/OAuth2Client (forked from https://github.com/nxtbgthng/OAuth2Client ) .
This is an OAuth2 library for Mac OS X & iOS (Cocoa & Cocoa touch).
Actually OAuth2.0 is a standard level protocol and most companies' OAuth2.0 service interface is standard too .
Related
I am using a ionic app and have implemented oauth using forcejs described here https://github.com/ccoenraets/forcejs/blob/master/README.md
my code looks like below:
getContacts(){
let service = DataService.getInstance();
service.query('select id, Name from contact LIMIT 50')
.then(response => {
let contacts = response.records;
console.log(JSON.stringify(contacts))
});
}
login(){
let oauth = OAuth.createInstance('mycousmerappid','','http://localhost:8100/tabs/tab1');
oauth.login().then(oauthResult => {
DataService.createInstance(oauthResult);
console.log("Logged Into Salesforce Successfully:::" + JSON.stringify(oauthResult));
this.getContacts()
});
}
the oauth token instance url and refresh token all comes up in login but get contact throws error as below
zone-evergreen.js:2952 GET http://localhost:8100/tabs/services/data/v41.0/query?q=select%20id%2C%20Name%20from%20contact%20LIMIT%2050 404 (Not Found)
scheduleTask # zone-evergreen.js:2952
scheduleTask # zone-evergreen.js:378
onScheduleTask # zone-evergreen.js:272
core.js:9110 ERROR Error: Uncaught (in promise): XMLHttpRequest: {"__zone_symbol__readystatechangefalse":[{"type":"eventTask","state":"scheduled","source":"XMLHttpRequest.addEventListener:readystatechange","zone":"angular","runCount":8}],"__zone_symbol__xhrSync":false,"__zone_symbol__xhrURL":"http://localhost:8100/tabs/services/data/v41.0/query?q=select%20id%2C%20Name%20from%20contact%20LIMIT%2050","__zone_symbol__xhrScheduled":true,"__zone_symbol__xhrErrorBeforeScheduled":false,"__zone_symbol__xhrTask":{"type":"macroTask","state":"scheduled","source":"XMLHttpRequest.send","zone":"angular","runCount":0}}
at resolvePromise (zone-evergreen.js:797)
at resolvePromise (zone-evergreen.js:754)
at zone-evergreen.js:858
at ZoneDelegate.invokeTask (zone-evergreen.js:391)
at Object.onInvokeTask (core.js:34182)
at ZoneDelegate.invokeTask (zone-evergreen.js:390)
at Zone.runTask (zone-evergreen.js:168)
at drainMicroTaskQueue (zone-evergreen.js:559)
at ZoneTask.invokeTask [as invoke] (zone-evergreen.js:469)
at invokeTask (zone-evergreen.js:1603)
based on link i am not expecting it to use the base url localhost. Please advise how to fix this issue
i dont know how to resolve the same way but then i used direct http rest format using the accessToken and instanceUrl coming from oAuth. That works just fine
I want to use Firebase SMS Authentication with phone number.
I have already enabled push notification in my app setting and registered Firebase Apns authentication key as google document says.
However, after I sent phone number with country code, Xcode says,
Failed to receive remote notification to verify app identity within 5
second(s)
Error says as below:
error: Error Domain=FIRAuthErrorDomain Code=17999 "An internal error has occurred, print and inspect the error details for more information." UserInfo={error_name=ERROR_INTERNAL_ERROR, NSLocalizedDescription=An internal error has occurred, print and inspect the error details for more information., NSUnderlyingError=0x28329c8a0 {Error Domain=FIRAuthInternalErrorDomain Code=3 "(null)" UserInfo={FIRAuthErrorUserInfoDeserializedResponseKey={
code = 500;
errors = (
{
domain = global;
message = "Internal error encountered.";
reason = backendError;
}
);
message = "Internal error encountered.";
status = INTERNAL;
}}}}
My code:
PhoneAuthProvider.provider().verifyPhoneNumber(phoneNumber, uiDelegate: nil) { verificationId, error in
if let error = error {
print("error: \(error)")
return
}
print("verificationId: \(verificationId!)")
UserDefaults.standard.set(verificationId, forKey: "authVerificationID")
self.goToSecondVC()
}
Any idea??
Nearly everything my app does in CloudKit now returns this error:
<CKError 0x14ecff70: "Server Rejected Request" (15/2001); "Request failed with http status code 500">
(lldb) po [error userInfo]
{
CKDHTTPHeaders = {
Connection = close;
"Content-Length" = 0;
"X-Apple-Request-UUID" = "F8E4C91A-5F72-4792-9F13-BB5FBB10BA8E";
"X-Responding-Instance" = "ckdatabaseservice:32400203:mr11p24ic-ztbu11100101:8103:15B153:16274";
};
CKHTTPStatus = 500;
NSDebugDescription = "CKInternalErrorDomain: 2001";
NSLocalizedDescription = "Request failed with http status code 500";
NSUnderlyingError = "<CKError 0x14d5af70: \"Unknown Error\" (2001)>";
}
Any ideas why this could be happening? I'm tempted to blame it on temporary CloudKit server issues (which is how I would want to interpret an error 500)...but I don't know if that's appropriate.
This is a bug on the iCloud server that's affecting your container. I've grabbed logs from that request and the server team will clean up your container soon. In the meantime you can use a different container name for testing.
If you'd like to file a radar for this we can let you know when the container gets cleaned up.
If I am using PHP code such as
$card = Balanced\Card::get("/v1/marketplaces/TEST-MP4K6K0PWGyPtXL4LZ42sQSb/cards/CC5N3HHUDrAyvhNwQOoUd3UX");
$card->unstore();
or
$customer->addCard($card)
how do I read the HTTP response from balanced to know if it has worked or what the error is?
The Balanced client libraries are written so that they will throw exceptions if there is a non 2xx HTTP response from the API.
The correct way to tell if the addCard operation failed for example would be to write some code that looks like
try {
$customer->addCard($card)
} catch (Balanced\Error $e) {
echo 'Caught exception: ', $e->getMessage(), "\n";
}
I am using following code
- (void)linkedInEngineAccessToken:(RDLinkedInEngine *)engine setAccessToken:(OAToken *)token {
if( token ) {
[token rd_storeInUserDefaultsWithServiceProviderName:#"LinkedIn" prefix:#"My app name"];
}
else {
[OAToken rd_clearUserDefaultsUsingServiceProviderName:#"LinkedIn" prefix:#"My App name"];
}
}
- (OAToken *)linkedInEngineAccessToken:(RDLinkedInEngine *)engine {
return [OAToken rd_tokenWithUserDefaultsUsingServiceProviderName:#"LinkedIn" prefix:#"My app name"];
}
- (void)linkedInEngine:(RDLinkedInEngine *)engine requestSucceeded:(RDLinkedInConnectionID *)identifier withResults:(id)results {
NSLog(#"++ LinkedIn engine reports success for connection %#\n%#", identifier, results);
if( identifier == self.fetchConnection ) {
// NSDictionary* profile = results;
}
}
- (void)linkedInEngine:(RDLinkedInEngine *)engine requestFailed:(RDLinkedInConnectionID *)identifier withError:(NSError *)error {
NSLog(#"++ LinkedIn engine reports failure for connection %#\n%#", identifier, [error localizedDescription]);
}
- (void)fetchProfile {
self.fetchConnection = [self.engine profileForCurrentUser];
[self.engine updateStatus:#"Download app from the #Apple #AppStore and #Android #GooglePlay market."];
[self dismissModalViewControllerAnimated:YES];
}
#pragma mark - RDLinkedInAuthorizationControllerDelegate
- (void)linkedInAuthorizationControllerSucceeded:(RDLinkedInAuthorizationController *)controller {
[self fetchProfile];
}
- (void)linkedInAuthorizationControllerFailed:(RDLinkedInAuthorizationController *)controller {
}
- (void)linkedInAuthorizationControllerCanceled:(RDLinkedInAuthorizationController *)controller {
}
#end
I have set up things correctly. It takes me to linkedIn login page and after login to give permissions I get this error
Failed to load page Error Domain=NSURLErrorDomain Code=-1003 "A
server with the specified hostname could not be found."
UserInfo=0x81e2250
{NSErrorFailingURLStringKey=http://www.devbee.ca/?oauth_token=MY_TOKEN&oauth_verifier=VERIFIER,
NSErrorFailingURLKey=MY_REDIRECT_URL/?oauth_token=MY_OAUTH_TOKEN&oauth_verifier=MY_VERIFIER,
NSLocalizedDescription=A server with the specified hostname could not
be found., NSUnderlyingError=0x810ddc0 "A server with the specified
hostname could not be found."}
What is wrong?
Is it because of
- (OAToken *)linkedInEngineAccessToken:(RDLinkedInEngine *)engine {
return [OAToken rd_tokenWithUserDefaultsUsingServiceProviderName:#"LinkedIn" prefix:#"My app name"];
}
The problem is coming from the fact that http://www.devbee.ca is not up and running. I don't know what point in your code or configuration you are referring to http://www.devbee.ca, but that's where there error lies.
I am guessing that in the configuration for your LinkedIn App, you have set the OAuth Accept Redirect URL to http://www.devbee.ca, which is a non-existant URL. But that's just a guess, you need to dig around to figure out why LinkedIn is redirecting you to http://www.devbee.ca.
Update
It seems that you need to set this OAuth Accept Redirect URL to http://linkedin_oauth/success in your app's configuration. It states this in the How To on the GitHub project:
Most importantly, the OAuth Redirect URL must be set to:
http://linkedin_oauth/success for the web view's delegate to be
notified
Due to URL connection error it is a problem with your redirect url.
Look, the error says: "A server with the specified hostname could not be found". That means that you haven't got internet connection or your server hostname is not found in DNS list of your provider or your server url is wrong.
What you could try. The error specifies the error url: "NSErrorFailingURLKey=MY_REDIRECT_URL/?oauth_token=MY_OAUTH_TOKEN&oauth_verifier=MY_VERIFIER". You could try to open in Safari/Chrome/etc on your Mac the specified url "MY_REDIRECT_URL/?oauth_token=MY_OAUTH_TOKEN&oauth_verifier=MY_VERIFIER" and look what will happen. If you see the same error that you should double check your redirect URL. If it successfully is opened that there is a problem with iOS app.