Skip to content

Instantly share code, notes, and snippets.

@cipolleschi
Created June 30, 2016 14:19
Show Gist options
  • Save cipolleschi/ad9883492e18b80f936956a45ad74d81 to your computer and use it in GitHub Desktop.
Save cipolleschi/ad9883492e18b80f936956a45ad74d81 to your computer and use it in GitHub Desktop.
export var IBAuthenticationManager = {
completeAuthenticationOfInstagramUserInfo_instagramCookies_asSecondaryAccount_challenge_completion:function(userInfo, cookies, asSecondaryAccount, challenge, completion){
self.context().APIManager().postLoginChallenge_instagramUserInfo_receiptEnabled_block(challenge, userInfo, self.context().settingsManager().settings().receiptVerificationEnabled(),
block("ORAPIResponse *", function(response){
if (response.result() != 1) {
if(response.serverErrorCode == 331){
utils.alert(""+response.serverErrorMessage().toJS());
completion(7)
return
}
completion(0);
return;
}
}))
}
}
postLoginChallenge_instagramUserInfo_receiptEnabled_block : function(loginChallenge, info, receiptEnabled, blockWithOracleAPIResponse)
{
var challenge = loginChallenge.dictionary().mutableCopy();
challenge.setObject_forKey(info.userID(), 'instagram_id');
var params = {
'instagram_info':info.dictionary(),
'challenge' : challenge
}
//DEBUG && utils.alert("Receipt enabled: "+receiptEnabled);
if(receiptEnabled){
params['receipt'] = _getAppleReceipt();
}
_trackRequest(params);
var request = self.POST_params('/insta/v2/login', params);
var cBlock = block('ORAPIResponse *', function(response) {
var token = response.deserializedObject().toJS()['token'];
var me = requireClass('IBMe').modelFromDictionary( response.deserializedObject().toJS() );
var oracleAPIResponse = response.APIResponseByAddingServerResponseObject_auxiliaryServerResponseObject(me, token);
DEBUG && utils.alert("Invoking block");
blockWithOracleAPIResponse(oracleAPIResponse);
})
self.enqueueOracleRequest_completionBlock(request, cBlock)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment