Skip to content

Commit

Permalink
Merge pull request #95 from ADmad/cake-4.x
Browse files Browse the repository at this point in the history
Cake 4.x
  • Loading branch information
ADmad authored Feb 21, 2021
2 parents 1b600be + fa72c5e commit 4e86ca3
Show file tree
Hide file tree
Showing 16 changed files with 168 additions and 184 deletions.
4 changes: 3 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,7 @@ insert_final_newline = true
trim_trailing_whitespace = true

[*.yml]
indent_style = space
indent_size = 2

[*.neon]
indent_style = tab
3 changes: 3 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,6 @@
phpunit.xml export-ignore
.travis.yml export-ignore
tests export-ignore
.phpstan.neon export-ignore
.psalm.xml export-ignore
.github export-ignore
74 changes: 74 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
name: CI

on: [push, pull_request]

jobs:
testsuite:
runs-on: ubuntu-18.04
strategy:
fail-fast: false
matrix:
php-version: ['7.4', '8.0']
composer-opts: ['']
include:
- php-version: '7.2'
composer-opts: '--prefer-lowest'

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: ${{ matrix.php-version }}
extension-csv: mbstring, intl
coverage: pcov

- name: Composer install
run: |
composer update ${{ matrix.composer-opts }}
- name: Run PHPUnit
run: |
if [[ ${{ matrix.php-version }} == '7.4' ]]; then
vendor/bin/phpunit --coverage-clover=coverage.xml
else
vendor/bin/phpunit
fi
- name: Code Coverage Report
if: matrix.php-version == '7.4'
uses: codecov/codecov-action@v1

cs-stan:
name: Coding Standard & Static Analysis
runs-on: ubuntu-18.04

steps:
- uses: actions/checkout@v1
with:
fetch-depth: 1

- name: Setup PHP
uses: shivammathur/setup-php@v2
with:
php-version: '7.4'
extension-csv: mbstring, intl
coverage: none
tools: cs2pr, psalm, phpstan

- name: Composer Install
run: composer require cakephp/cakephp-codesniffer:^4.1

- name: Run phpcs
run: vendor/bin/phpcs --report=checkstyle -q --standard=vendor/cakephp/cakephp-codesniffer/CakePHP src/ tests/ | cs2pr

- name: Run psalm
if: success() || failure()
run: psalm --output-format=github

- name: Run phpstan
if: success() || failure()
run: phpstan analyse
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/composer.lock
/phpunit.xml
/vendor
.phpunit.result.cache
10 changes: 0 additions & 10 deletions .stickler.yml

This file was deleted.

10 changes: 0 additions & 10 deletions .styleci.yml

This file was deleted.

49 changes: 0 additions & 49 deletions .travis.yml

This file was deleted.

2 changes: 1 addition & 1 deletion LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
The MIT License (MIT)

Copyright (c) 2015-2018 ADmad
Copyright (c) 2015-Present ADmad

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
Expand Down
23 changes: 9 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# CakePHP JWT Authenticate plugin

[![Build Status](https://img.shields.io/travis/ADmad/cakephp-jwt-auth/master.svg?style=flat-square)](https://travis-ci.org/ADmad/cakephp-jwt-auth)
[![Coverage](https://img.shields.io/codecov/c/github/ADmad/cakephp-jwt-auth.svg?style=flat-square)](https://codecov.io/github/ADmad/cakephp-jwt-auth)
[![Build Status](https://img.shields.io/github/workflow/status/ADmad/cakephp-jwt-auth/CI/master?style=flat-square)](https://github.com/ADmad/cakephp-jwt-auth/actions?query=workflow%3ACI+branch%3Amaster)
[![Coverage Status](https://img.shields.io/codecov/c/github/ADmad/cakephp-jwt-auth.svg?style=flat-square)](https://codecov.io/github/ADmad/cakephp-jwt-auth)
[![Total Downloads](https://img.shields.io/packagist/dt/ADmad/cakephp-jwt-auth.svg?style=flat-square)](https://packagist.org/packages/ADmad/cakephp-jwt-auth)
[![License](https://img.shields.io/badge/license-MIT-blue.svg?style=flat-square)](LICENSE.txt)

Expand All @@ -17,14 +17,7 @@ composer require admad/cakephp-jwt-auth

## Usage

In your app's `config/bootstrap.php` add:

```php
// In config/bootstrap.php
Plugin::load('ADmad/JwtAuth');
```

or using cake's console:
Load the plugin using Cake's console:

```sh
./bin/cake plugin load ADmad/JwtAuth
Expand All @@ -36,7 +29,7 @@ Setup `AuthComponent`:

```php
// In your controller, for e.g. src/Api/AppController.php
public function initialize()
public function initialize(): void
{
parent::initialize();

Expand Down Expand Up @@ -97,9 +90,9 @@ The authentication class checks for the token in two locations:
RewriteCond %{HTTP:Authorization} ^(.*)
RewriteRule .* - [e=HTTP_AUTHORIZATION:%1]
```

or

```
SetEnvIf Authorization "(.*)" HTTP_AUTHORIZATION=$1
```
Expand All @@ -109,9 +102,11 @@ The authentication class checks for the token in two locations:
You can use `\Firebase\JWT\JWT::encode()` of the [firebase/php-jwt](https://github.com/firebase/php-jwt)
lib, which this plugin depends on, to generate tokens.

**The payload should have the "sub" (subject) claim whose value is used to query the
**The payload must have the "sub" (subject) claim whose value is used to query the
Users model and find record matching the "id" field.**

Ideally you should also specify the token expiry time using `exp` claim.

You can set the `queryDatasource` option to `false` to directly return the token's
payload as user info without querying datasource for matching user record.

Expand Down
5 changes: 2 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@
"issues":"https://github.com/ADmad/cakephp-jwt-auth/issues"
},
"require": {
"cakephp/cakephp": "^3.5",
"cakephp/cakephp": "^4.0",
"firebase/php-jwt": "^5.0"
},
"require-dev": {
"cakephp/chronos": "^1.1",
"phpunit/phpunit": "^5.7.14|^6.0"
"phpunit/phpunit": "~8.5.0"
},
"autoload": {
"psr-4": {
Expand Down
6 changes: 4 additions & 2 deletions phpstan.neon
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
parameters:
ignoreErrors:
- '#Call to an undefined method object::getConfig\(\)#'
level: 6
checkMissingIterableValueType: false
paths:
- src/
1 change: 0 additions & 1 deletion phpunit.xml.dist
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
colors="true"
processIsolation="false"
stopOnFailure="false"
syntaxCheck="false"
bootstrap="./tests/bootstrap.php"
>
<php>
Expand Down
18 changes: 18 additions & 0 deletions psalm.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0"?>
<psalm
errorLevel="2"
resolveFromConfigFile="true"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="https://getpsalm.org/schema/config"
xsi:schemaLocation="https://getpsalm.org/schema/config vendor/vimeo/psalm/config.xsd"
>
<projectFiles>
<directory name="src" />
<ignoreFiles>
<directory name="vendor" />
</ignoreFiles>
</projectFiles>
<issueHandlers>
<PropertyNotSetInConstructor errorLevel="suppress"/>
</issueHandlers>
</psalm>
Loading

0 comments on commit 4e86ca3

Please sign in to comment.