Exemplo n.º 1
0
 /// <summary>
 /// Creates an instance of NotesController and implements authentication.
 /// </summary>
 public NotesController()
     :
     base(DynamoDbClient, null, () =>
 {
     // Extracting userId from 'Authorization' HTTP header and using it as a predefined HashKey value.
     try
     {
         return(AuthRoutine.GetUserIdFromAuthorizationHeader());
     }
     catch (UnauthorizedAccessException)
     {
         // Throwing Web API-specific exception to return 401.
         throw new HttpResponseException(HttpStatusCode.Unauthorized);
     }
 }, () => new RedisTableCache(RedisConn))
 {
 }
Exemplo n.º 2
0
        private void ItmViaPlexTv_Click(object sender, EventArgs e)
        {
            try
            {
                //check if there's a connection before trying to update the authentication token
                if (Internet.IsConnected)
                {
                    var auth = AuthRoutine.GetAuthToken();

                    var r = auth.Result;

                    switch (r)
                    {
                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.Success:
                        if (ApplyToken(auth.Token))
                        {
                            UIMessages.Info(
                                @"Successfully connected to Plex.tv. You can now load and connect to your servers/relays.",
                                @"Success");
                            LoadServers(true);

                            //status update
                            SetInterfaceAuthenticationStatus(true);
                        }
                        else
                        {
                            UIMessages.Error(@"An unknown error occurred; we couldn't apply your account token.");
                        }

                        break;

                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.Cancelled:     //nothing
                        break;

                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.Failed:     //alert the user to the failure
                        UIMessages.Error(
                            @"Failed to apply your account token; the ticket authority didn't authorise the transaction or values were not valid.");
                        break;

                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.Error:     //alert the user to the error
                        UIMessages.Error(@"An unknown error occurred; we couldn't apply your account token.");
                        break;

                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.Invalid:     //alert the user
                        UIMessages.Error(@"Failed to apply your account token; details were invalid.");
                        break;

                    case PlexAPI.LoginHandler.Auth.Enums.AuthStatus.IncorrectResponse:
                        UIMessages.Error(
                            @"Failed to get an authentication ticket from Plex.tv; an incorrectly formatted response was received.");
                        break;

                    default:
                        throw new ArgumentOutOfRangeException();
                    }
                }
                else
                // trying to connect on no connection will not end well; alert the user.
                {
                    UIMessages.Warning(
                        @"No internet connection. Please connect to a network before attempting to authenticate.",
                        @"Network Error");
                }
            }
            catch (Exception ex)
            {
                LoggingHelpers.RecordException(ex.Message, "ConnectionError");
                UIMessages.Error("Connection Error:\n\n" + ex, @"Connection Error");
            }
        }