ChatterBox.Server.WNSAuthentication.AuthenticateWithWNS C# (CSharp) Method

AuthenticateWithWNS() public method

public AuthenticateWithWNS ( ) : void
return void
        public async void AuthenticateWithWNS()
        {
            IsRefreshInProgress = true;

            var urlEncodedSid = HttpUtility.UrlEncode(WNS_PACKAGE_SECURITY_IDENTIFIER);
            var urlEncodedSecret = HttpUtility.UrlEncode(WNS_SECRET_KEY);

            var body = String.Format(PayloadFormat, urlEncodedSid, urlEncodedSecret, AccessScope);

            string response = null;
            Exception exception = null;
            using (var client = new WebClient())
            {
                client.Headers.Add("Content-Type", UrlEncoded);
                try
                {
                    response = await client.UploadStringTaskAsync(new Uri(AccessTokenUrl), body);
                }
                catch (Exception e)
                {
                    exception = e;
                    Debug.WriteLine(String.Format("Failed WNS authentication. Error: {0}",e.Message));
                }
            }

            if (exception == null && response != null)
            {
                oAuthToken = GetOAuthTokenFromJson(response);
                ScheduleTokenRefreshing();
            }

            IsRefreshInProgress = false;
            OnAuthenticated?.Invoke();
        }