public static int DoServiceAuthorizationWithPolicy(string username, string serviceId, string privateKey, bool jailbreakDetection, int?factors, string geofence, string apiURL)
        {
            List <Location> locations = null;

            // parse geofence input
            if (!string.IsNullOrWhiteSpace(geofence))
            {
                try
                {
                    var parts = geofence.Split(':');
                    if (parts.Length != 3)
                    {
                        Console.WriteLine("geofence should be in the format lat:lon:radius:name");
                        return(1);
                    }
                    var lat  = double.Parse(parts[0]);
                    var lon  = double.Parse(parts[1]);
                    var rad  = double.Parse(parts[2]);
                    var name = parts[3];

                    locations = new List <Location>();
                    locations.Add(new Location(rad, lat, lon, name));
                }
                catch (FormatException)
                {
                    Console.WriteLine("geofence parsing failed");
                    return(1);
                }
            }
            Console.WriteLine($"Using policy: factors: {factors}, locations: {locations?.Count}, geofence: {geofence}, jailbreak: {jailbreakDetection}");
            var policy = new AuthPolicy(
                jailbreakDetection: jailbreakDetection,
                locations: locations,
                requiredFactors: factors
                );

            var serviceClient = ClientFactories.MakeServiceClient(serviceId, privateKey, apiURL);

            return(SharedServiceHelpers.DoAuthorizationRequest(serviceClient, username, false, policy: policy));
        }
Exemple #2
0
        /// <summary>
        /// Link a device to a user. This starts the process which must be completed via the authenticator app for this directory
        /// </summary>
        public static int DoDeviceLink(string directoryId, string privateKey, string userId, string apiURL, int?ttl, bool?useWebhook)
        {
            try
            {
                var directoryClient = ClientFactories.MakeDirectoryClient(directoryId, privateKey, apiURL);
                Console.WriteLine("Sending request to begin device link ... ");
                var deviceLinkResponse = directoryClient.LinkDevice(userId, ttl);
                Console.WriteLine($"Successfully sent link request. \n Device ID: {deviceLinkResponse.DeviceId} \n Use the following code to complete the link: {deviceLinkResponse.Code}");

                if (useWebhook == true)
                {
                    Console.WriteLine($"You wanted to retrieve the webhook so I will open a port!");
                    var openWebhookPort = SharedServiceHelpers.HandleWebhook(directoryClient);
                }
            }
            catch (BaseException e)
            {
                Console.WriteLine($"There was an error beginning the device link for the user with ID {userId}. Error: {e.Message}");
            }

            return(0);
        }
Exemple #3
0
        public static int DoServiceAuth(string orgId, string privateKey, string serviceId, string userId, string apiURL, bool?useWebhook)
        {
            var serviceClient = ClientFactories.MakeOrganizationServiceClient(orgId, privateKey, serviceId, apiURL);

            return(SharedServiceHelpers.DoAuthorizationRequest(serviceClient, userId, useWebhook));
        }
        public static int DoSessionStart(string username, string serviceId, string privateKey, string apiURL)
        {
            var serviceClient = ClientFactories.MakeServiceClient(serviceId, privateKey, apiURL);

            return(SharedServiceHelpers.DoSessionStart(serviceClient, username));
        }
        public static object DoServiceAuthorizationCancel(string serviceId, string privateKey, string apiURL, string authorizationRequestId)
        {
            var serviceClient = ClientFactories.MakeServiceClient(serviceId, privateKey, apiURL);

            return(SharedServiceHelpers.DoAuthorizationCancel(serviceClient, authorizationRequestId));
        }
        public static int DoServiceAuthorization(string username, string serviceId, string privateKey, string apiURL, string context, int?ttl, string title, string pushTitle, string pushBody, int?fraudDenialreasons, int?nonFraudDenialreasons, bool?useWebhook = false, bool?advancedWebhook = false)
        {
            var serviceClient = ClientFactories.MakeServiceClient(serviceId, privateKey, apiURL);

            return(SharedServiceHelpers.DoAuthorizationRequest(serviceClient, username, useWebhook, advancedWebhook, context, null, title, ttl, pushTitle, pushBody, fraudDenialreasons, nonFraudDenialreasons));
        }
Exemple #7
0
        /// <summary>
        /// End a session for a directory service and user
        /// </summary>
        public static int DoDirectoryServiceSessionEnd(string directoryId, string privateKey, string serviceId, string userId, string apiURL)
        {
            var serviceClient = ClientFactories.MakeDirectoryServiceClient(directoryId, privateKey, serviceId, apiURL);

            return(SharedServiceHelpers.DoSessionEnd(serviceClient, userId));
        }