Anton Tropashko
Anton Tropashko

Reputation: 5806

From Airwatch SDK, how to I get the current logged in username/certificate

Airwatch documentation is gawdawful. So bear with me. From Airwatch SDK, how to I get the currently logged in username/user certificate?

Upvotes: 0

Views: 172

Answers (2)

Fandango68
Fandango68

Reputation: 4868

It's in the API

            //setup authorization profile
            var client = new RestClient("https://enterprise.telstra.com/api/mdm");
            client.Authenticator=new HttpBasicAuthenticator("#####", "#######");
            var request = new RestRequest("devices/search", DataFormat.Json);
            request.AddHeader("aw-tenant-code", "##########");

            //get the data as json
            var response = client.Get(request);
            if (response.IsSuccessful)
            {
                //serialize the data into the Devices[] array RootObject
                RootObject ro = new RootObject();
                ro = JsonConvert.DeserializeObject<RootObject>(response.Content);

                //create a new DataTable with columns specifically required
                DataTable dt = new DataTable("tblDevices");
                dt.Columns.Add("AssetNumber");
                dt.Columns.Add("DeviceFriendlyName");
                dt.Columns.Add("IMEI");
                dt.Columns.Add("MacAddress");
                dt.Columns.Add("Model");
                dt.Columns.Add("DeviceType");
                dt.Columns.Add("OEMinfo");
                dt.Columns.Add("Platform");
                dt.Columns.Add("SerialNumber");
                dt.Columns.Add("UserEmailAddress");
                dt.Columns.Add("UserName");

                //iterate through each device data and add it into a DataRow
                foreach(Device d in ro.Devices)
                {
                    DataRow dr = dt.NewRow();

                    dr["UserName"] = d.UserName.ToUpper();  //uppercase the userid

                    //add the row to the table
                    dt.Rows.Add(dr);
                }

Upvotes: 1

Anton Tropashko
Anton Tropashko

Reputation: 5806

With godly help from the client

    AWController.clientInstance().retrieveStoredPublicCertificates { payload, error in
        if let _ = error {
            return
        }
        guard let payload = payload as? [String : [PKCS12Certificate]] else {
            return
        }
        processCertificates(payload)
        NotificationCenter.default.post(name: .awSDKCeritificatesReceived,
                                        object: payload)
    }

Upvotes: 0

Related Questions