Git Product home page Git Product logo

passport-custom-request-grant's People

Contributors

erictendian avatar jmancusi avatar mikemclin avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

passport-custom-request-grant's Issues

ClientRepositoryInterface is not instantiable while building

After install and implement show this error for whatever i done (Postman, migrate...): Illuminate\Contracts\Container\BindingResolutionException: Target [League\OAuth2\Server\Repositories\ClientRepositoryInterface] is not instantiable while building [League\OAuth2\Server\AuthorizationServer]. in /var/www/wa/clean-api/vendor/illuminate/container/Container.php:763.

And what is exactly this "bySsoToken"?

My Custon provider

`use Laravel\Passport\Bridge\RefreshTokenRepository;
use Laravel\Passport\Bridge\UserRepository;
use Laravel\Passport\Passport;
use Laravel\Passport\PassportServiceProvider;
use League\OAuth2\Server\AuthorizationServer;
use League\OAuth2\Server\Grant\PasswordGrant;
/**

  • Class CustomQueueServiceProvider
  • @Package App\Providers
    /
    class SSOGrantProvider extends PassportServiceProvider
    {
    /
    *
    • Bootstrap any application services.

    • @return void
      /
      public function boot()
      {
      //$ClientInterface = app()->make('WA\vendor\league\oauth2-server\Repositories\ClientRepositoryInterface');
      }
      /
      *

    • Register the service provider.

    • @return void
      */
      public function register()
      {

      app(AuthorizationServer::class)->enableGrantType($this->makeSSOGrant(), Passport::tokensExpireIn());
      }
      /**

    • Create and configure a Password grant instance.

    • @return PasswordGrant
      */
      protected function makeSSOGrant()
      {
      $grant = new SSOGrant(
      $this->app->make(UserRepository::class),
      $this->app->make(RefreshTokenRepository::class)
      );
      $grant->setRefreshTokenTTL(Passport::refreshTokensExpireIn());
      return $grant;
      }
      }`

Model

`use Illuminate\Http\Request;
use Laravel\Passport\Bridge\User;
use League\OAuth2\Server\Entities\UserEntityInterface;
use League\OAuth2\Server\Exception\OAuthServerException;
use League\OAuth2\Server\Grant\AbstractGrant;
use League\OAuth2\Server\Repositories\RefreshTokenRepositoryInterface;
use League\OAuth2\Server\Repositories\UserRepositoryInterface;
use League\OAuth2\Server\RequestEvent;
use League\OAuth2\Server\ResponseTypes\ResponseTypeInterface;
use Psr\Http\Message\ServerRequestInterface;

/**

  • SSO grant class.
    /
    class SSOGrant extends AbstractGrant
    {
    /
    *
    • @param UserRepositoryInterface $userRepository
    • @param RefreshTokenRepositoryInterface $refreshTokenRepository
      /
      public function __construct(
      UserRepositoryInterface $userRepository,
      RefreshTokenRepositoryInterface $refreshTokenRepository
      )
      {
      $this->setUserRepository($userRepository);
      $this->setRefreshTokenRepository($refreshTokenRepository);
      $this->refreshTokenTTL = new \DateInterval('P1M');
      }
      /
      *
    • {@inheritdoc}
      /
      public function respondToAccessTokenRequest(
      ServerRequestInterface $request,
      ResponseTypeInterface $responseType,
      \DateInterval $accessTokenTTL
      )
      {
      // Validate request
      $client = $this->validateClient($request);
      $scopes = $this->validateScopes($this->getRequestParameter('scope', $request));
      $user = $this->validateUser($request);
      // Finalize the requested scopes
      $scopes = $this->scopeRepository->finalizeScopes($scopes, $this->getIdentifier(), $client, $user->getIdentifier());
      // Issue and persist new tokens
      $accessToken = $this->issueAccessToken($accessTokenTTL, $client, $user->getIdentifier(), $scopes);
      $refreshToken = $this->issueRefreshToken($accessToken);
      // Inject tokens into response
      $responseType->setAccessToken($accessToken);
      $responseType->setRefreshToken($refreshToken);
      return $responseType;
      }
      /
      *
    • {@inheritdoc}
      /
      public function getIdentifier()
      {
      return 'sso';
      }
      /
      *
    • @param ServerRequestInterface $request
    • @return UserEntityInterface
    • @throws OAuthServerException
      /
      protected function validateUser(ServerRequestInterface $request)
      {
      $laravelRequest = new Request($request->getParsedBody());
      $user = $this->getUserEntityByRequest($laravelRequest);
      if ($user instanceof UserEntityInterface === false) {
      $this->getEmitter()->emit(new RequestEvent(RequestEvent::USER_AUTHENTICATION_FAILED, $request));
      throw OAuthServerException::invalidCredentials();
      }
      return $user;
      }
      /
      *
    • Retrieve user by request.
    • @param \Illuminate\Http\Request $request
    • @return \Laravel\Passport\Bridge\User|null
    • @throws \League\OAuth2\Server\Exception\OAuthServerException
      */
      protected function getUserEntityByRequest(Request $request)
      {
      if (is_null($model = config('auth.providers.users.model'))) {
      throw OAuthServerException::serverError('Unable to determine user model from configuration.');
      }
      if (method_exists($model, 'byPassportSSOGrantRequest')) {
      $user = (new $model)->byPassportSSOGrantRequest($request);
      } else {
      throw OAuthServerException::serverError('Unable to find byPassportSSOGrantRequest method on user model.');
      }
      return ($user) ? new User($user->id) : null;
      }
      }`
      User functions

`public function byPassportSSOGrantRequest(Request $request)
{
try {
if ($request->get('sso')) {
return $this->SSOGrantVerify($request->get('sso'));

    }
} catch (\Exception $e) {
    throw OAuthServerException::accessDenied($e->getMessage());
}
return null;

}

 public function SSOGrantVerify(Request $request)
{
    
    $laravelUser = Cache::get('saml2user_'.$request);

    if (!isset($laravelUser)) {
        return false;
    } else {
        return $laravelUser['attributes'];
    }
}

}
`

passport 3.0

Hi,

I have problem with your package because I have laravel 5.4 and passport 3.0 and your package is not compatible:

  Problem 1
    - Installation request for mikemclin/passport-custom-request-grant ^1.0 -> satisfiable by mikemclin/passport-custom-request-grant[1.0.0].
    - mikemclin/passport-custom-request-grant 1.0.0 requires laravel/passport ^2.0 -> satisfiable by laravel/passport[2.0.x-dev, v2.0.0, v2.0.1, v2.0.10, v2.0.11, v2.0.2, v2.0.3, v2.0.4, v2.0.5, v2.0.6, v2.0.7, v2.0.8, v2.0.9] but these conflict with your requirements or minimum-stability.

Coud you fix it?
Thanks

Class hash does not exist

I downloaded the package but I'm getting a "Class hash does not exist" error when I send the request. Here's the stack trace:

ReflectionException in Container.php line 734: Class hash does not exist in Container.php line 734 at ReflectionClass->__construct('hash') in Container.php line 734 at Container->build('hash', array()) in Container.php line 629 at Container->make('hash', array()) in Application.php line 710 at Application->make('Illuminate\Contracts\Hashing\Hasher') in Container.php line 849 at Container->resolveClass(object(ReflectionParameter)) in Container.php line 804 at Container->getDependencies(array(object(ReflectionParameter)), array()) in Container.php line 775 at Container->build('Laravel\Passport\Bridge\UserRepository', array()) in Container.php line 629 at Container->make('Laravel\Passport\Bridge\UserRepository', array()) in Application.php line 710 at Application->make('Laravel\Passport\Bridge\UserRepository') in PassportServiceProvider.php line 138 at PassportServiceProvider->makePasswordGrant() in PassportServiceProvider.php line 80 at PassportServiceProvider->Laravel\Passport\{closure}(object(AuthorizationServer)) in helpers.php line 814 at tap(object(AuthorizationServer), object(Closure)) in PassportServiceProvider.php line 86 at PassportServiceProvider->Laravel\Passport\{closure}(object(Application), array()) in Container.php line 731 at Container->build(object(Closure), array()) in Container.php line 629 at Container->make('League\OAuth2\Server\AuthorizationServer', array()) in Application.php line 710 at Application->make('League\OAuth2\Server\AuthorizationServer', array()) in helpers.php line 106 at app('League\OAuth2\Server\AuthorizationServer') in CustomRequestGrantProvider.php line 35 at CustomRequestGrantProvider->register() in Application.php line 566 at Application->register(object(CustomRequestGrantProvider)) in ProviderRepository.php line 74 at ProviderRepository->load(array('Illuminate\Auth\AuthServiceProvider', 'Illuminate\Broadcasting\BroadcastServiceProvider', 'Illuminate\Bus\BusServiceProvider', 'Illuminate\Cache\CacheServiceProvider', 'Illuminate\Foundation\Providers\ConsoleSupportServiceProvider', 'Illuminate\Cookie\CookieServiceProvider', 'Illuminate\Database\DatabaseServiceProvider', 'Illuminate\Encryption\EncryptionServiceProvider', 'Illuminate\Filesystem\FilesystemServiceProvider', 'Illuminate\Foundation\Providers\FoundationServiceProvider', 'Illuminate\Hashing\HashServiceProvider', 'Illuminate\Mail\MailServiceProvider', 'Illuminate\Notifications\NotificationServiceProvider', 'Illuminate\Pagination\PaginationServiceProvider', 'Illuminate\Pipeline\PipelineServiceProvider', 'Illuminate\Queue\QueueServiceProvider', 'Illuminate\Redis\RedisServiceProvider', 'Illuminate\Auth\Passwords\PasswordResetServiceProvider', 'Illuminate\Session\SessionServiceProvider', 'Illuminate\Translation\TranslationServiceProvider', 'Illuminate\Validation\ValidationServiceProvider', 'Illuminate\View\ViewServiceProvider', 'Laravel\Passport\PassportServiceProvider', 'MikeMcLin\Passport\CustomRequestGrantProvider', 'LogSalud\Providers\AppServiceProvider', 'LogSalud\Providers\AuthServiceProvider', 'LogSalud\Providers\EventServiceProvider', 'LogSalud\Providers\RouteServiceProvider')) in Application.php line 541 at Application->registerConfiguredProviders() in RegisterProviders.php line 17 at RegisterProviders->bootstrap(object(Application)) in Application.php line 203 at Application->bootstrapWith(array('Illuminate\Foundation\Bootstrap\DetectEnvironment', 'Illuminate\Foundation\Bootstrap\LoadConfiguration', 'Illuminate\Foundation\Bootstrap\ConfigureLogging', 'Illuminate\Foundation\Bootstrap\HandleExceptions', 'Illuminate\Foundation\Bootstrap\RegisterFacades', 'Illuminate\Foundation\Bootstrap\RegisterProviders', 'Illuminate\Foundation\Bootstrap\BootProviders')) in Kernel.php line 253 at Kernel->bootstrap() in Kernel.php line 144 at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 116 at Kernel->handle(object(Request)) in index.php line 54

Let me know if you need any more info. Thanks.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.