Authenticate
- Method
- Example C#
- Example JS
Authenticate(AuthenticateRequest)
Authentication using different types of credentials.
Declaration
public AuthenticateResponse Authenticate(AuthenticateRequest request)
Parameters
TYPE | NAME | DESCRIPTION |
---|---|---|
AuthenticateRequest | request | MFACredentials SSOCredentials StoreCredentials UserCredentials AuthTokenCredentials |
Returns
TYPE | DESCRIPTION |
---|---|
AuthenticateResponse |
public enum AuthenticationType
{
User,
SSO256,
SSO512,
AuthToken
}
private AuthenticateResponse Authenticate(AuthenticationType authType)
{
using (RDCWebServiceClient client = new RDCWebServiceClient())
{
switch (authType)
{
case AuthenticationType.User:
return client.Authenticate(Authenticate_User());
case AuthenticationType.SSO256:
case AuthenticationType.SSO512:
return client.Authenticate(Authenticate_SSO(authType));
case AuthenticationType.AuthToken:
return client.Authenticate(Authenticate_AuthToken());
}
}
return null;
}
private AuthenticateRequest Authenticate_User()
{
return new AuthenticateRequest()
{
Credentials = new UserCredentials()
{
UserName = "TestUser",
Password = "TestPassword",
PhoneKey = GetPhoneKey(),
Company = "Company",
},
DeviceTracking = new DeviceTracking()
{
AppBundleId = "com.testbank.deposit", //get from your app
AppVersion = "1.0.1433", //get from your app
DeviceModel = "iPhone 6s", //get from system info
DeviceSystemName = "iPhone OS", //get from system info
DeviceSystemVersion = "9.3.2", //get from system info
Vendor = "XYZ" //Place the integrating company name here
},
RequestDate = DateTime.Now,
RequestId = NewRequestId()
};
}
private AuthenticateRequest Authenticate_AuthToken()
{
return new AuthenticateRequest()
{
Credentials = new AuthTokenCredentials()
{
UserName = "TestUser",
DeviceId = "TestDeviceId",
PhoneKey = GetPhoneKey(),
Company = "Company",
SignedDigestBase64 = "SignedDigestBase64"
},
DeviceTracking = new DeviceTracking()
{
AppBundleId = "com.testbank.deposit", //get from your app
AppVersion = "1.0.1433", //get from your app
DeviceModel = "iPhone 6s", //get from system info
DeviceSystemName = "iPhone OS", //get from system info
DeviceSystemVersion = "9.3.2", //get from system info
Vendor = "XYZ" //Place the integrating company name here
},
RequestDate = DateTime.Now,
RequestId = NewRequestId()
};
}
private AuthenticateResponse Authenticate_MFA(MFADetail details)
{
using (RDCWebServiceClient client = new RDCWebServiceClient())
{
return client.Authenticate(new AuthenticateRequest()
{
Credentials = new MFACredentials()
{
MFA = details,
PhoneKey = GetPhoneKey()
}
});
}
}
private AuthenticateRequest Authenticate_SSO(AuthenticationType authType)
{
var ret = new AuthenticateRequest()
{
Credentials = new SSOCredentials()
{
FIIdentifier = "abcd",
UserNumber = "999",
SaltValue = Guid.NewGuid().ToString(),
Timestamp = DateTime.Parse("1/1/2016"),
PhoneKey = GetPhoneKey()
},
DeviceTracking = new DeviceTracking()
{
AppBundleId = "com.testbank.deposit", //get from your app
AppVersion = "1.0.1433", //get from your app
DeviceModel = "iPhone 6s", //get from system info
DeviceSystemName = "iPhone OS", //get from system info
DeviceSystemVersion = "9.3.2", //get from system info
Vendor = "EPS"
},
RequestId = NewRequestId(),
RequestDate = DateTime.Now,
};
CalculateHash(ret.Credentials as SSOCredentials, authType);
return ret;
}
private string CalculateHash(SSOCredentials creds, AuthenticationType authType)
{
string shared_secret = "This is a secret!!!!";
string Concatenated = creds.UserNumber + creds.Timestamp.ToString() + creds.FIIdentifier + shared_secret + creds.SaltValue;
byte[] output = null;
HashAlgorithm hashAlgorithm = null;
switch (authType)
{
case AuthenticationType.SSO256:
hashAlgorithm = new SHA256CryptoServiceProvider();
break;
case AuthenticationType.SSO512:
hashAlgorithm = new SHA512CryptoServiceProvider();
break;
}
if (hashAlgorithm != null)
{
output = hashAlgorithm.ComputeHash(Encoding.ASCII.GetBytes(Concatenated));
hashAlgorithm.Dispose();
hashAlgorithm = null;
}
return ToHexString(output);
}
private string ToHexString(byte[] bytes)
{
char[] hexDigits = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'a', 'b', 'c', 'd', 'e', 'f' };
char[] chars = new char[bytes.Length * 2];
for (int i = 0; i < bytes.Length; i++)
{
int b = bytes[i];
chars[i * 2] = hexDigits[b >> 4];
chars[i * 2 + 1] = hexDigits[b & 0xF];
}
return new string(chars);
}
function Authenticate(authType, success, error) {
var request = new XMLHttpRequest();
request.setRequestHeader("Content-type", "application/json; charset=utf-8");
request.open(
"POST",
"http://localhost/mobile/RDCWebService.svc/Authenticate",
true
);
request.onreadystatechange = function () {
if (request.readyState === 4) {
if (request.status !== 200) {
return error(request.statusText);
}
var response = JSON.parse(request.responseText);
switch (response.Result) {
case Result.Error:
case Result.ValidationError:
return error(response);
case Result.Success:
default:
return success(response);
}
}
};
request.send(getAuthenticationCredentials(authType));
}
function getAuthenticationCredentials(authType) {
switch (authType) {
case AuthenticateType.User: {
var user = new Customer();
user.PhoneKey = "1234";
user.Company = "Company";
user.Password = "TestPassword";
user.UserName = "TestUser";
user.DeviceTracking.AppBundleId = "eps.mobile.rdc";
user.DeviceTracking.AppVersion = "1.0";
user.DeviceTracking.DeviceModel = "iPhone7.2";
user.DeviceTracking.DeviceSystemName = "iPhone OS";
user.DeviceTracking.DeviceSystemVersion = "8.3";
user.DeviceTracking.Vendor = "XYZ";
return JSON.stringify(user);
}
case AuthenticateType.SSO256:
case AuthenticateType.SSO512: {
var ssoUser = new Customer();
ssoUser.UserNumber = 999;
ssoUser.FIIdentifier = "abcd";
ssoUser.Hash = "1234"; //Calculate the hash via SHA256 or SHA512
ssoUser.SaltValue = "1234";
ssoUser.Timestamp = "/Date(" + new Date().toJSON() + ")/";
ssoUser.DeviceTracking.AppBundleId = "eps.mobile.rdc";
ssoUser.DeviceTracking.AppVersion = "1.0";
ssoUser.DeviceTracking.DeviceModel = "iPhone7.2";
ssoUser.DeviceTracking.DeviceSystemName = "iPhone OS";
ssoUser.DeviceTracking.DeviceSystemVersion = "8.3";
ssoUser.DeviceTracking.Vendor = "EPS";
return JSON.stringify(ssoUser);
}
case AuthenticateType.AuthToken: {
var user = new Customer();
user.PhoneKey = "1234";
user.Company = "Company";
user.DeviceId = "1234";
user.UserName = "TestUser";
user.SignedDigestBase64 = "SignedDigestBase64";
user.DeviceTracking.AppBundleId = "eps.mobile.rdc";
user.DeviceTracking.AppVersion = "1.0";
user.DeviceTracking.DeviceModel = "iPhone7.2";
user.DeviceTracking.DeviceSystemName = "iPhone OS";
user.DeviceTracking.DeviceSystemVersion = "8.3";
user.DeviceTracking.Vendor = "XYZ";
return JSON.stringify(user);
}
default:
return null;
}
}