FRAPushMechanismFactory.m revision fc9bee101f530464b5da5a9602697f40a91c5c50
/*
* The contents of this file are subject to the terms of the Common Development and
* Distribution License (the License). You may not use this file except in compliance with the
* License.
*
* You can obtain a copy of the License at legal/CDDLv1.0.txt. See the License for the
* specific language governing permission and limitations under the License.
*
* When distributing Covered Software, include this CDDL Header Notice in each file and include
* the License file at legal/CDDLv1.0.txt. If applicable, add the following below the CDDL
* Header, with the fields enclosed by brackets [] replaced by your own identifying
* information: "Portions copyright [year] [name of copyright owner]".
*
* Copyright 2016 ForgeRock AS.
*/
#import "FRAIdentity.h"
#import "FRAIdentityDatabase.h"
#import "FRAMechanismFactory.h"
#import "FRAMessageUtils.h"
#import "FRAMockURLProtocol.h"
#import "FRAPushMechanism.h"
#import "FRAPushMechanismFactory.h"
#import "FRAQRUtils.h"
#import "FRASerialization.h"
/*! QR code key for the secret. */
/*! QR code key for the authentication endpoint url. */
/*! QR code key for the regsitration endpoint url. */
/*! QR code key for the message. */
/*! QR code key for the background colour of the mechanism. */
/*! QR code key for the registration challange. */
/*! QR code key for the mechanism image. */
/*! QR code key for the issuer name. */
}
if (self) {
}
return self;
}
- (FRAMechanism *) buildMechanism:(NSURL *)uri database:(FRAIdentityDatabase *)database model:(FRAIdentityModel *)model {
NSString *regEndpoint = [FRAQRUtils decodeURL:[query objectForKey:REGISTRATION_ENDPOINT_URL_QR_KEY]];
NSString *authEndpoint = [FRAQRUtils decodeURL:[query objectForKey:AUTHENTICATION_ENDPOINT_URL_QR_KEY]];
if (nil == secret || nil == regEndpoint || nil == authEndpoint || nil == messageId || nil == challenge || nil == issuer) {
}
FRAPushMechanism* mechanism = [FRAPushMechanism pushMechanismWithDatabase:database authEndpoint:authEndpoint secret:secret];
FRAIdentity *identity = [self getIdentity:uri database:database label:_label issuer:issuer imagePath:image backgroundColor:backgroundColor];
FRAIdentity *search = [model identityWithIssuer:[identity issuer] accountName:[identity accountName]];
// TODO: Error Handling
}
} else {
if ([self checkForDuplicate]) {
// TODO: populate NSError
return nil;
}
}
// TODO: Error Handling
}
[self registerMechanismWithEndpoint:regEndpoint secret:secret challenge:challenge messageId:messageId mechanismUid:mechanism.mechanismUID identity:identity mechanism:mechanism];
return mechanism;
}
return nil;
}
return nil;
}
// Get the path and strip it of its leading '/'
return nil;
}
}
return nil;
}
// Get issuer and label
return nil;
}
} else {
_issuer = @"";
}
// Parse query
// Value can contain '=' symbols, so look for first symbol.
continue;
}
}
return query;
}
- (bool) checkForDuplicate {
return false;
}
/*!
* Resolves the Identity from the URL that has been provided.
* @return an initialised but not persisted Identity.
*/
- (FRAIdentity *)getIdentity:(NSURL*)url database:(FRAIdentityDatabase *)database label:(NSString *)label issuer:(NSString *)issuer imagePath:(NSString *)imagePath backgroundColor:(NSString*) backgroundColor {
return [FRAIdentity identityWithDatabase:database accountName:label issuer:issuer image:[NSURL URLWithString:imagePath] backgroundColor:backgroundColor];
}
return false;
}
return true;
}
- (NSString *) getSupportedProtocol {
return @"pushauth";
}
- (void) registerMechanismWithEndpoint:(NSString *)regEndpoint secret:(NSString *)secret challenge:(NSString *)c messageId:(NSString *)messageId mechanismUid:(NSString *)uid identity:(FRAIdentity *)identity mechanism:(FRAMechanism *)mechanism{
deviceId = @"";
} else {
}
@"mechanismUid":uid,
@"deviceId":deviceId,
@"deviceType":@"ios",
@"communicationType":@"apns"
}
if (200 != statusCode) {
// TODO: inform user about failure
// TODO: Handle Error
}
}
}];
}
@end