app/Http/Middleware/InstalledAppUserDataAccessGate.php
/**
     * This middleware just ensures that only users who have installed an application can have their account
     * authenticated from the application.
     * The only other way to gain access to such an app would be authenticating via the token URL mode.
     *
     * @param Request $request
     * @param Closure $next
     *
     * @return mixed
     */
This middleware just ensures that only users who have installed an application can have their account
authenticated from the application.
The only other way to gain access to such an app would be authenticating via the token URL mode.

@param Request $request
@param Closure $next

@return mixed
This middleware just ensures that only users who have installed an application can have their account authenticated from the application . The only other way to gain access to such an app would be authenticating via the token URL mode . @param Request $request @param Closure $next @return mixed
public function handle(Request $request, Closure $next)
    {
        $response = $next($request);
        if (empty($user = $request->user())) {
            return $response;
        }
        $clientId = $request->input('client_id');
        if (ends_with($request->path(), 'oauth/token') && !empty($clientId) && !is_numeric($clientId)) {
            list($clientId) = app(Hashids::class)->decode($clientId);
            $application = Application::with(['user'])->where('oauth_client_id', $clientId)->first();
            $company = $user->company;
            if (!$application->is_published) {
                if ($company->id !== $application->user->company_id) {
                    throw new ApplicationAccessDeniedException(
                        'Only people invited into your organisation can be application testers.'
                    );
                }
                return $response;
            }
            $installCount = $company->applicationInstalls()->where('application_id', $application->id)->count();
            if ($installCount === 0) {
                throw new ApplicationAccessDeniedException(
                    $application->name . ' has not yet been installed by this user.'
                );
            }
        }
        return $response;
    }
public function handle ( Request $ request , Closure $ next ) { $ response = $ next ( $ request ) ; if ( empty ( $ user = $ request -> user ( ) ) ) { return $ response ; } $ clientId = $ request -> input ( 'client_id' ) ; if ( ends_with ( $ request -> path ( ) , 'oauth/token' ) && ! empty ( $ clientId ) && ! is_numeric ( $ clientId ) ) { list ( $ clientId ) = app ( Hashids :: class ) -> decode ( $ clientId ) ; $ application = Application :: with ( [ 'user' ] ) -> where ( 'oauth_client_id' , $ clientId ) -> first ( ) ; $ company = $ user -> company ; if ( ! $ application -> is_published ) { if ( $ company -> id !== $ application -> user -> company_id ) { throw new ApplicationAccessDeniedException ( 'Only people invited into your organisation can be application testers.' ) ; } return $ response ; } $ installCount = $ company -> applicationInstalls ( ) -> where ( 'application_id' , $ application -> id ) -> count ( ) ; if ( $ installCount === 0 ) { throw new ApplicationAccessDeniedException ( $ application -> name . ' has not yet been installed by this user.' ) ; } } return $ response ; }
This middleware just ensures that only users who have installed an application can have their account
 authenticated from the application.
This middleware just ensures that only users who have installed an application can have their account authenticated from the application .
# we get the client ID # this was a login request -- if the app isn't installed by the user, we reject the request # we'll only bother about those clients that are not numeric -- all non-numeric client IDs are for external # apps # get the actual client id # get the application # get the authenticated company # probably in testing mode -- so, we'll only allow people in the same organisation as the creating account # has it been installed # we throw an exception