Skip to content

Commit

Permalink
Merge pull request #1 from bizley/2.0.1
Browse files Browse the repository at this point in the history
2.0.1
  • Loading branch information
Bizley authored Nov 28, 2020
2 parents b772268 + 3d97f73 commit bb49147
Show file tree
Hide file tree
Showing 17 changed files with 223 additions and 86 deletions.
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
/.github export-ignore
/tests export-ignore
/phpunit.xml.dist export-ignore
10 changes: 10 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
version: 2
updates:
- package-ecosystem: "github-actions"
directory: "/"
schedule:
interval: "daily"
- package-ecosystem: "composer"
directory: "/"
schedule:
interval: "daily"
47 changes: 47 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
name: Tests

on:
pull_request:
push:
branches:
- "2.x"

jobs:
Infection:
name: PHP ${{ matrix.php }}
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
php: ['7.1', '7.2', '7.3', '7.4']

steps:
- name: Checkout
uses: actions/checkout@v2

- name: Install PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php }}
extensions: mbstring, intl, mysql
coverage: "none"
env:
COMPOSER_TOKEN: ${{ secrets.GITHUB_TOKEN }}
update: true

- name: Get composer cache directory
id: composer-cache
run: echo "::set-output name=dir::$(composer config cache-files-dir)"

- name: Cache composer dependencies
uses: actions/[email protected]
with:
path: ${{ steps.composer-cache.outputs.dir }}
key: ${{ runner.os }}-composer-${{ hashFiles('**/composer.json') }}
restore-keys: ${{ runner.os }}-composer-

- name: Install dependencies
run: composer update --prefer-dist --no-interaction --no-progress --optimize-autoloader

- name: Run PHPUnit
run: vendor/bin/phpunit
28 changes: 0 additions & 28 deletions .travis.yml

This file was deleted.

76 changes: 76 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Contributor Covenant Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to making participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies both within project spaces and in public spaces
when an individual is representing the project or its community. Examples of
representing a project or community include using an official project e-mail
address, posting via an official social media account, or acting as an appointed
representative at an online or offline event. Representation of a project may be
further defined and clarified by project maintainers.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at [email protected]. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
![Latest Stable Version](https://img.shields.io/packagist/v/bizley/jwt.svg)
[![Total Downloads](https://img.shields.io/packagist/dt/bizley/jwt.svg)](https://packagist.org/packages/bizley/jwt)
![License](https://img.shields.io/packagist/l/bizley/jwt.svg)
[![Build Status](https://travis-ci.org/bizley/yii2-jwt.svg?branch=master)](https://travis-ci.org/bizley/yii2-jwt)

# JWT Integration For Yii 2

Expand All @@ -10,6 +9,8 @@ This extension provides the [JWT](https://github.com/lcobucci/jwt) integration f

> This is fork of [sizeg/yii2-jwt](https://github.com/sizeg/yii2-jwt) package
This package uses lcobucci/jwt v3. For v4 install `bizley/jwt:^3.0`.

## Installation

Add the package to your `composer.json`:
Expand Down Expand Up @@ -67,4 +68,4 @@ Please refer to the [lcobucci/jwt Documentation](https://github.com/lcobucci/jwt

## JSON Web Tokens

- https://jwt.io
- https://jwt.io
8 changes: 4 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
"keywords": ["yii2", "jwt", "jws", "token", "authentication"],
"license": "Apache-2.0",
"authors": [
{
"name": "Dmitriy Demin",
"email": "[email protected]"
},
{
"name": "Pawel Bizley Brzozowski",
"email": "[email protected]"
},
{
"name": "Dmitriy Demin",
"email": "[email protected]"
}
],
"support": {
Expand Down
4 changes: 1 addition & 3 deletions phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
<?xml version="1.0" encoding="utf-8"?>
<phpunit bootstrap="./tests/bootstrap.php"
colors="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true">
convertDeprecationsToExceptions="false">
<testsuites>
<testsuite name="Yii 2 JWT Test Suite">
<directory>./tests</directory>
Expand Down
9 changes: 6 additions & 3 deletions src/Jwt.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace bizley\jwt;

Expand All @@ -10,6 +12,7 @@
use Lcobucci\JWT\Token;
use Lcobucci\JWT\ValidationData;
use Yii;
use yii\base\Component;

/**
* JSON Web Token implementation based on lcobucci/jwt library.
Expand All @@ -18,7 +21,7 @@
* @author Dmitriy Demin <[email protected]> original package
* @author Paweł Bizley Brzozowski <[email protected]> since 2.0 (fork)
*/
class Jwt extends \yii\base\Component
class Jwt extends Component
{
/**
* @var array Token signers
Expand Down Expand Up @@ -61,7 +64,7 @@ public function getBuilder(?Encoder $encoder = null, ?Factory $claimFactory = nu
*/
public function getParser(?Decoder $decoder = null, ?Factory $claimFactory = null): Parser
{
return new Parser($decoder, $claimFactory);
return new Parser($decoder, $claimFactory); // $claimFactory not used anymore in lcobucci/jwt 3.4
}

/**
Expand Down
16 changes: 11 additions & 5 deletions src/JwtHttpBearerAuth.php
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
<?php declare(strict_types=1);
<?php

declare(strict_types=1);

namespace bizley\jwt;

use Lcobucci\JWT\Token;
use yii\base\InvalidConfigException;
use yii\di\Instance;
use yii\filters\auth\HttpBearerAuth;
use yii\web\IdentityInterface;
use yii\web\Request;
use yii\web\Response;
use yii\web\UnauthorizedHttpException;
use yii\web\User;

/**
* JwtHttpBearerAuth is an action filter that supports the authentication method based on HTTP Bearer JSON Web Token.
Expand All @@ -27,7 +33,7 @@
* @author Dmitriy Demin <[email protected]> original package
* @author Paweł Bizley Brzozowski <[email protected]> since 2.0 (fork)
*/
class JwtHttpBearerAuth extends \yii\filters\auth\HttpBearerAuth
class JwtHttpBearerAuth extends HttpBearerAuth
{
/**
* @var string|array|Jwt application component ID of the JWT handler, configuration array, or JWT handler object itself.
Expand Down Expand Up @@ -55,7 +61,7 @@ public function init(): void
{
parent::init();

$this->jwt = \yii\di\Instance::ensure($this->jwt, Jwt::class);
$this->jwt = Instance::ensure($this->jwt, Jwt::class);

if (empty($this->pattern)) {
throw new InvalidConfigException('You must provide pattern to use to extract the HTTP authentication value!');
Expand All @@ -64,8 +70,8 @@ public function init(): void

/**
* Authenticates the current user.
* @param \yii\web\User $user
* @param \yii\web\Request $request
* @param User $user
* @param Request $request
* @param Response $response
* @return IdentityInterface the authenticated user identity. If authentication information is not provided, null will be returned.
* @throws UnauthorizedHttpException if authentication information is provided but is invalid.
Expand Down
Loading

0 comments on commit bb49147

Please sign in to comment.