ArranJacques / laravel-aws-cognito-auth

An authentication driver for Laravel for authenticating users in AWS Cognito User Pools.
Other
74 stars 26 forks source link

handleError should return Closure result #4

Closed zoul0813 closed 7 years ago

zoul0813 commented 7 years ago
    /**
     * Handle a failed authentication attempt.
     *
     * @param \Pallant\LaravelAwsCognitoAuth\AuthAttempt $response
     * @param mixed $handler
     * @return mixed
     */
    protected function handleError(AuthAttempt $response, $handler = null)
    {
        if (is_object($handler) AND method_exists($handler, 'handle')) {
            return $handler->handle(new AuthAttemptException($response));
        } elseif ($handler == AWS_COGNITO_AUTH_THROW_EXCEPTION) {
            throw new AuthAttemptException($response);
        } elseif ($handler == AWS_COGNITO_AUTH_RETURN_ATTEMPT) {
            return $response;
        } elseif ($handler instanceof Closure) {
            // RETURN here
            return $handler(new AuthAttemptException($response));
        }

        return false;
    }

When executing the Closure, the result should be returned. This allows the Closure to re-attempt authentication (for example, after successfully completing a challenge) by returning true or false.

ArranJacques commented 7 years ago

Hi

Only just had a chance to look at this. Yeah this is a good idea. If you want to submit a pull request to address the issue then I'll merge it in.

If not I'm away for the rest of this week so I'll take a look myself when I'm back next week.

Thanks

zoul0813 commented 7 years ago

Ref #5