Esempio n. 1
0
        public static int DoDirectoryDeviceList(string orgId, string privateKey, string directoryId, string userId, string apiURL)
        {
            var directoryClient = ClientFactories.MakeOrganizationDirectoryClient(orgId, privateKey, directoryId, apiURL);

            try
            {
                var deviceListResponse = directoryClient.GetLinkedDevices(userId);

                Console.WriteLine();
                Console.WriteLine($"Devices ({deviceListResponse.Count} found): ");
                Console.WriteLine("-------- ");
                Console.WriteLine();

                foreach (var device in deviceListResponse)
                {
                    Console.WriteLine($" > Device {device.Id}");
                    Console.WriteLine($"    Type: {device.Type}");
                    Console.WriteLine($"    Status: {device.Status}");
                    Console.WriteLine($"    Name: {device.Name}");
                }
                Console.WriteLine();
            }
            catch (BaseException e)
            {
                Console.WriteLine($"There was an error listing the devices for the user with ID {userId}. Error: {e.Message}");
            }

            return(0);
        }
Esempio n. 2
0
        /// <summary>
        /// List all active sessions across all services for a user within this directory
        /// </summary>
        public static int DoSessionList(string directoryId, string privateKey, string userId, string apiURL)
        {
            try
            {
                var directoryClient = ClientFactories.MakeDirectoryClient(directoryId, privateKey, apiURL);
                Console.WriteLine("Sending request to get list of sessions ... ");
                var sessions = directoryClient.GetAllServiceSessions(userId);

                Console.WriteLine();
                Console.WriteLine($"Sessions ({sessions.Count} found): ");
                Console.WriteLine("-------- ");
                Console.WriteLine();

                foreach (var session in sessions)
                {
                    Console.WriteLine($"Session: serviceId = {session.ServiceId}, serviceName = {session.ServiceName}, created = {session.Created}");
                }
            }
            catch (BaseException e)
            {
                Console.WriteLine($"There was an error getting the active session list for the user {userId} in the directory {directoryId}. Error: {e.Message}");
            }

            return(0);
        }
Esempio n. 3
0
        public static int DoUpdateDirectoryWebhookUrl(string orgId, string privateKey, string directoryId, string apiURL, string webkhookUrl)
        {
            var orgClient = ClientFactories.MakeOrganizationClient(orgId, privateKey, apiURL);
            var directory = orgClient.GetDirectory(Guid.Parse(directoryId));

            orgClient.UpdateDirectory(Guid.Parse(directoryId), directory.Active, directory.AndroidKey, null, true, webkhookUrl);
            return(0);
        }
Esempio n. 4
0
        /// <summary>
        /// Unlink a device from a user
        /// </summary>
        public static int DoDeviceUnlink(string directoryId, string privateKey, string userId, string deviceId, string apiURL)
        {
            try
            {
                var directoryClient = ClientFactories.MakeDirectoryClient(directoryId, privateKey, apiURL);
                Console.WriteLine("Sending request to unlink device ... ");
                directoryClient.UnlinkDevice(userId, deviceId);
                Console.WriteLine($"Successfully sent unlink request for device id {deviceId} on user with ID {userId}.");
            }
            catch (BaseException e)
            {
                Console.WriteLine($"There was an error unlinking the device {deviceId} for the user with ID {userId}. Error: {e.Message}");
            }

            return(0);
        }
Esempio n. 5
0
        /// <summary>
        /// Purges all user sessions across all services for a user within this directory
        /// </summary>
        public static int DoSessionPurge(string directoryId, string privateKey, string userId, string apiURL)
        {
            try
            {
                var directoryClient = ClientFactories.MakeDirectoryClient(directoryId, privateKey, apiURL);
                Console.WriteLine("Sending request to end all sessions ... ");
                directoryClient.EndAllServiceSessions(userId);
                Console.WriteLine("Done.");
            }
            catch (BaseException e)
            {
                Console.WriteLine($"There was an error ending the sessions for the user {userId} in the directory {directoryId}. Error: {e.Message}");
            }

            return(0);
        }
        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));
        }
Esempio n. 7
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);
        }
Esempio n. 8
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));
        }
Esempio n. 10
0
        public static object DoServiceAuthorizationCancel(string serviceId, string privateKey, string apiURL, string authorizationRequestId)
        {
            var serviceClient = ClientFactories.MakeServiceClient(serviceId, privateKey, apiURL);

            return(SharedServiceHelpers.DoAuthorizationCancel(serviceClient, authorizationRequestId));
        }
Esempio n. 11
0
        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));
        }
Esempio n. 12
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));
        }