Ejemplo n.º 1
0
 async void PerformAuth1TestRequests(AuthProvider ap, Account account)
 {
     foreach (KeyValuePair<string, string> p in account.Properties)
         System.Diagnostics.Debug.WriteLine("Property: Key:" + p.Key + " Value:" + p.Value);
     try
     {
         foreach (string requestUrl in ap.apiRequests)
         {
             OAuth1Request request = new OAuth1Request("GET", new Uri(requestUrl), null, account, false);
             IResponse response = await request.GetResponseAsync();
             ResponseText = response.GetResponseText();
         }
     }
     catch (Exception ex)
     {
         ErrorText = "PerformAuth1TestRequests: Exception:";
         for (Exception inner = ex; inner != null; inner = inner.InnerException)
         {
             ErrorText += "Message:" + inner.Message + "\n";
         }
         foreach (KeyValuePair<string, string> p in account.Properties)
             ErrorText += "Key:" + p.Key + " Value:" + p.Value + "\n";
     }
 }
Ejemplo n.º 2
0
 async void PerformAuth2TestRequests(AuthProvider ap, Account account)
 {
     try
     {
         ResponseText = ""; // clear response display string
         foreach (KeyValuePair<string, string> p in account.Properties)
             System.Diagnostics.Debug.WriteLine("Property: Key:" + p.Key + " Value:" + p.Value);
         System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: Count:" + ap.apiRequests.Count);
         foreach (string requestUrl in ap.apiRequests)
         {
             System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: Url:" + requestUrl);
             ResponseText += "Request Url:" + requestUrl + "\n";
             OAuth2Request request = new OAuth2Request("GET", new Uri(requestUrl), null, account);
             if (!string.IsNullOrEmpty(ap.SubstituteRequestAccessToken))
                 request.AccessTokenParameterName = ap.SubstituteRequestAccessToken;
             IResponse response = await request.GetResponseAsync();
             System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: StatusCode:" + response.StatusCode + " ResponseUri:" + response.ResponseUri);
             System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: Headers:");
             foreach (KeyValuePair<string, string> h in response.Headers)
                 System.Diagnostics.Debug.WriteLine("Header: Key:" + h.Key + " Value:" + h.Value);
             ResponseText += "Response(" + response.StatusCode + "):";
             string r = response.GetResponseText();
             ResponseText += r + "\n";
         }
     }
     catch (Exception ex)
     {
         ErrorText += "Exception: PerformAuth2TestRequests: Message:" + ex.Message + "\n";
         foreach (KeyValuePair<string, string> p in account.Properties)
             ErrorText += "Key:" + p.Key + " Value:" + p.Value + "\n";
     }
 }
Ejemplo n.º 3
0
 public IOAuth2Request OAuth2Request(string method, Uri url, Dictionary<string, string> parameters, Account account)
 {
     Xamarin.Auth.OAuth2Request xrequest = new Xamarin.Auth.OAuth2Request(method, url, parameters, (Xamarin.Auth.Account)account.xAccount);
     return new OAuth2RequestImpl(xrequest);
 }
Ejemplo n.º 4
0
 public void Save(Account account, string serviceId)
 {
     xAccountStore.Save((Xamarin.Auth.Account)account.xAccount, serviceId);
 }
        /// <summary>
        /// This method is called after authentication is successfull.
        /// Implement functionality that is useful as initial server communication. 
        /// </summary>
        /// <param name="account"></param>
        async void PerformAuth2TestRequests(Account account)
        {
            Authorized = true;
            App.SuccessfulLoginAction();

            try
            {

                /*
                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests before looop");


                foreach (KeyValuePair<string, string> p in account.Properties)
                {
                    System.Diagnostics.Debug.WriteLine("Property: Key:" + p.Key + " Value:" + p.Value);
                }
                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests before looop");

                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: Url:" + AuthProvider.ApiRequests);
                System.Diagnostics.Debug.WriteLine("Request Url:" + AuthProvider.ApiRequests);
                */
                Uri requestLocalToken = new Uri(AuthProvider.ApiRequests + account.Properties["access_token"]);
                System.Diagnostics.Debug.WriteLine("Requesting local token");
                System.Diagnostics.Debug.WriteLine("Using access_token: " + account.Properties["access_token"]);
                OAuth2Request request1 = new OAuth2Request("GET", requestLocalToken, null, account);
                //OAuth2Request request1 = new OAuth2Request("GET", requestLocalToken, null, null);

                IResponse response1 = await request1.GetResponseAsync();
                System.Diagnostics.Debug.WriteLine("After Response");


                Dictionary<string, string> responseDict = JsonConvert.DeserializeObject<Dictionary<string, string>>(response1.GetResponseText());


                string localToken = "";
                string username = "";

                if (response1.StatusCode == 200)
                {
                    System.Diagnostics.Debug.WriteLine("Response code from backend: 200");
                    localToken = responseDict["access_token"];
                    username = responseDict["userName"];
                    System.Diagnostics.Debug.WriteLine("username: "******"localToken: " + localToken);

                    StudentsController sc = new StudentsController();
                    DbStudent dbStudent = new DbStudent();
                    if (dbStudent.CheckIfStudentExist(username))
                    {
                        System.Diagnostics.Debug.WriteLine("Student did exist");
                        Student student = dbStudent.GetStudent(username);
                        student.accessToken = localToken;
                        dbStudent.UpdateStudent(student);
                        DevicesController dc = new DevicesController();
                        dc.UpdateServersDb();
                    }
                    else
                    {
                        System.Diagnostics.Debug.WriteLine("Student did not exist");
                        dbStudent.DeleteAllStudents();
                        Student student = new Student();
                        student.username = username;
                        student.accessToken = localToken;
                        student.receiveNotifications = true;
                        student.receiveJobNotifications = true;
                        student.receiveProjectNotifications = true;
                        dbStudent.InsertStudent(student);
                        DevicesController dc = new DevicesController();
                        DbDevice dbDevice = new DbDevice();
                        dbDevice.FixStudentForeignKey(username);
                        dc.UpdateServersDb();
                    }
                }
                /*
                string studentEndpoint = "http://kompetansetorgetserver1.azurewebsites.net/api/v1/students";
                Uri testAuthorize = new Uri(studentEndpoint);


                //authorization: bearer b2Dvqzi9Ux_FAjbBYat6PE-LgNGKL_HDBWbnJ3Fb9cwfjaE8NQdqcvC8jwSB5QJUIVRog_gQQPjaRI0DT7ahu7TEpqP28URtPr1LjgaV - liCqgIuTdSHW_NqD3qh - 5shVh - h7TCin7XNHq8GSkGg5qtOlcHeFPSZ4xMwMbw5_1rBfKYJr3w0_D5R9jk0hJPEfJldCTYcawatz7wVfbmz0qKHAkrKxZyaqum6IHJWdczWz5K26RCfZWMwEmK1uLN5

                var client = new HttpClient();
                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests before Setting AuthenticationHeaderValue");
                client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("bearer", localToken);
                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests after Setting AuthenticationHeaderValue");
            System.Diagnostics.Debug.WriteLine(client.DefaultRequestHeaders.Authorization.Parameter);


                var response = await client.GetAsync(testAuthorize);


                System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: StatusCode:" + response.StatusCode);
                                                 // + " ResponseUri:" + response.ResponseUri);
                //System.Diagnostics.Debug.WriteLine("PerformAuth2TestRequests: Headers:");


                foreach (KeyValuePair<string, string> h in response.Headers)
                {
                    System.Diagnostics.Debug.WriteLine("Header: Key:" + h.Key + " Value:" + h.Value);
                } 
                System.Diagnostics.Debug.WriteLine("Response(" + response.StatusCode);
                string jsonString = await response.Content.ReadAsStringAsync();
                System.Diagnostics.Debug.WriteLine(jsonString);
                */
                // TODO Implement relevant GET, PUT or POST Requests
                // Notifies the app that the login was successful and that its safe to shift page.
                Authorized = true;
                App.SuccessfulLoginAction();
            }
            catch (Exception ex)
            {
                System.Diagnostics.Debug.WriteLine("Exception: PerformAuth2TestRequests: Message:" + ex.Message);
                foreach (KeyValuePair<string, string> p in account.Properties)
                {
                    System.Diagnostics.Debug.WriteLine("Key:" + p.Key + " Value:" + p.Value);
                }
            }

        }
Ejemplo n.º 6
0
 public IOAuth1Request OAuth1Request(string method, Uri url, Dictionary<string, string> parameters, Account account, bool includeMultipartInSignature = false)
 {
     Xamarin.Auth.OAuth1Request xrequest = new Xamarin.Auth.OAuth1Request(method, url, parameters, (Xamarin.Auth.Account)account.xAccount, includeMultipartInSignature);
     return new OAuth1RequestImpl(xrequest);
 }
Ejemplo n.º 7
0
 public OAuth1Request(string method, Uri url, Dictionary<string, string> parameters, Account account, bool includeMultiPartInSignature)
 {
     request = Auth.auth.auth1.OAuth1Request(method, url, parameters, account, includeMultiPartInSignature);
 }
Ejemplo n.º 8
0
 public AuthenticatorCompletedEventArgs(Account account)
 {
     Account = account;
 }
Ejemplo n.º 9
0
 public void Delete(Account account, string serviceId) { xAccountStore.Delete(account, serviceId); }
Ejemplo n.º 10
0
 public void Save(Account account, string serviceId) { xAccountStore.Save(account, serviceId); }
Ejemplo n.º 11
0
 public OAuth2Request(string method, Uri url, Dictionary<string, string> parameters, Account account)
 {
     request = Auth.auth.auth2.OAuth2Request(method, url, parameters, account);
 }