Authorization

Requests:

+[TLAuthRequests authorizeAccountWithPhoneNumber:phoneCodeHash:phoneCode:password:] - authorize user by phone number.

+[TLAuthRequests signInByEmailWithEmail:password:] - authorize user by email/password

+[TLAuthRequests authorizeByOAuthWithType:authorizationCode:redirectUrl:] - authorize user by OAuth

Authorization handling example:

This category allows to store authorization data.

@implementation TLAuthorization (TPDPersist)

- (TPDAccountDbo *)pTPD_TLAA_P_persistWithOrganizationId:(int32_t)orgId {
    let tlAccount = self.account;
    let users = tlAccount.users;
    let authInfo = [self tpd_authInfo];

    BOOL dropDb = ![TPDKeychain isAccountAuthed];

    [TPDKeychain setValue:authInfo forKey:TPDKeychainAuthInfo];

    if (dropDb) {
        [TPDDatabaseQueue.sharedDbQueue drop];
    }
    else if (orgId) {
        [TPDDatabaseQueue.sharedDbQueue dropDataForOrganization:orgId];
    }

    let account = [TPDAccountDbo accountFromTLAccount:tlAccount];

    [TPDDatabaseQueue.sharedDbQueue inTransactionOnSharedDatabase:
     ^(TPDDatabase *db, TPDRollbackMarker *rollbackMarker) {
         if (!dropDb) {
             [db deleteAllFrom:[TPDOrganizationDbo tableInfo] rollback:rollbackMarker];
         }

         [account saveInDb:db rollback:rollbackMarker];
     }];

    [users enumerateObjectsUsingBlock:^(TLUser * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
        let user = [TPDUserDbo userFromTLUser:obj];

        [TPDDatabaseQueue.sharedDbQueue inTransaction:^(TPDDatabase *db, TPDRollbackMarker *rollbackMarker) {
            [user saveInDb:db rollback:rollbackMarker];
        } forOrganization:obj.organizationId];
    }];

    return account;
}

- (TPDAccountDbo *)tpd_persist {
    return [self pTPD_TLAA_P_persistWithOrganizationId:0];
}

- (TPDAccountDbo *)tpd_persistForOrganization:(int32_t)orgId {
    assert(orgId);

    return [self pTPD_TLAA_P_persistWithOrganizationId:orgId];
}

@end

Usage:

Last updated