react-native-oauth icon indicating copy to clipboard operation
react-native-oauth copied to clipboard

Referencing a non existent

Open SailingSteve opened this issue 8 years ago • 0 comments

When using the tools for a Twitter only oAuth, I ran into an exception that prevented me from progressing. At line 306

NSString *clientID = ((DCTOAuth2Credential *) existingAccount).clientID;

I was receiving a DCTOAuth1Credential, which the code cast to a DCTOAuth2Credential and attempted to reference a non-existent clientID field. The following change allowed me to get my app working.

RCT_EXPORT_METHOD(authorize:(NSString *)providerName
                  opts:(NSDictionary *) opts
                  callback:(RCTResponseSenderBlock)callback)
{
    OAuthManager *manager = [OAuthManager sharedManager];
    [manager clearPending];
    NSMutableDictionary *cfg = [[manager getConfigForProvider:providerName] mutableCopy];
    
    DCTAuthAccount *existingAccount = [manager accountForProvider:providerName];
    // Fix to avoid dereferencing an  non existent DCTOAuth2Credential clientID field in a DCTOAuth1Credential
    NSString *clientID = ([providerName isEqualToString:@"google"]) ? ((DCTOAuth2Credential *) existingAccount).clientID : (NSString *)nil;
    // End of fix

    if (([providerName isEqualToString:@"google"] && existingAccount && clientID != nil)
        || (![providerName isEqualToString:@"google"] && existingAccount != nil)) {
        if ([existingAccount isAuthorized]) {

SailingSteve avatar Sep 22 '17 18:09 SailingSteve