Skip to content

Commit dfc2324

Browse files
g105bGreg Bowler
andauthored
Merge latest change into master (#18)
* wip: cipher upgrade * build: upgrade to stable cipher * feature: upgrade for 2022 provider * feature: response data classes * feature: user class * test: fix tests * docs: explain unit tests * ci: update step versions * ci: upgrade workflow * ci: bump step versions * test: fix test warnings caused by mocks * feature: switch to json serialisation for language interoperability * feature: switch to json serialisation for language interoperability * feature: logout uri * feature: fake login for #14 * tweak: check property is set before access * tweak: get all kvp * tweak: override and remove session data on logout * feature: append existing query string * tweak: pass in email you would like * tweak: allow multiple underscores --------- Co-authored-by: Greg Bowler <greg.bowler@g105b.com>
1 parent 77b7d2c commit dfc2324

24 files changed

Lines changed: 1563 additions & 1059 deletions

.github/workflows/ci.yml

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,49 @@ name: CI
33
on: [push]
44

55
jobs:
6-
build:
7-
runs-on: [ubuntu-latest]
6+
composer:
7+
runs-on: ubuntu-latest
88

99
steps:
10-
- uses: actions/checkout@v1
10+
- uses: actions/checkout@v3
1111

12-
- name: Cache PHP dependencies
13-
uses: actions/cache@v1
12+
- name: Cache Composer dependencies
13+
uses: actions/cache@v3
1414
with:
15-
path: vendor
16-
key: ${{ runner.OS }}-build-${{ hashFiles('**/composer.lock') }}
15+
path: /tmp/composer-cache
16+
key: ${{ runner.os }}-${{ hashFiles('**/composer.lock') }}
1717

18-
- uses: php-actions/composer@v1
18+
- name: Composer
19+
uses: php-actions/composer@v6
20+
with:
21+
php_version: '8.1'
22+
23+
- name: Archive build
24+
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./
1925

20-
- name: Upload build for test runner
21-
uses: actions/upload-artifact@v1
26+
- name: Upload build archive for test runners
27+
uses: actions/upload-artifact@v3
2228
with:
2329
name: build-artifact
24-
path: ./
30+
path: /tmp/github-actions
2531

26-
test:
27-
runs-on: [ubuntu-latest]
28-
needs: [build]
32+
phpunit:
33+
runs-on: ubuntu-latest
34+
needs: [ composer ]
2935

3036
steps:
31-
- uses: actions/download-artifact@v1
37+
- uses: actions/download-artifact@v3
3238
with:
3339
name: build-artifact
34-
path: ./
40+
path: /tmp/github-actions
3541

36-
- uses: php-actions/phpunit@v1
42+
- name: Extract build archive
43+
run: tar -xvf /tmp/github-actions/build.tar ./
44+
45+
- name: PHP Unit tests
46+
uses: php-actions/phpunit@v3
47+
with:
48+
php_version: '8.1'
49+
php_extensions: xdebug
50+
configuration: test/phpunit/phpunit.xml
51+
bootstrap: vendor/autoload.php

README.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ To use this repository, your application must be registered to obtain a client k
88
Basic usage
99
-----------
1010

11-
With the following PHP code below, you can display a log in button that, when clicked, changes to a log out button and displays a greeting to the logged in user.
11+
With the following PHP code below, you can display a login button that, when clicked, changes to a logout button and displays a greeting to the logged-in user.
1212

1313
```php
1414
<?php
@@ -23,7 +23,7 @@ define("CLIENT_KEY", "1234567890abcdef");
2323
// Authentication steps passed via the query string from the remote provider.
2424
$auth = new Authenticator(
2525
CLIENT_KEY,
26-
$_SERVER["REQUEST_URI"]
26+
$_SERVER["REQUEST_URI"],
2727
);
2828

2929
// Handle authentication login/logout action via the querystring:
@@ -41,6 +41,11 @@ elseif(isset($_GET["logout"])) {
4141
// Authentication is handled by Authwave, so you can trust "isLoggedIn"
4242
// as a mechanism for protecting your sensitive information.
4343
if($auth->isLoggedIn()) {
44+
// Available methods:
45+
// $auth->getId(); // a unique string in ULID format - use this to store in your database
46+
// $auth->getEmail(); // the current email of the user (could change)
47+
// $auth->getField($name); // any extra field your application is configured to take upon user signup
48+
4449
echo <<<HTML
4550
<p>You are logged in as <strong>{$auth->getEmail()}</strong></p>
4651
<p><a href="?logout">Log out</a></p>
@@ -52,4 +57,13 @@ else {
5257
<p><a href="?login">Log in</a></p>
5358
HTML;
5459
}
55-
```
60+
```
61+
62+
Running unit tests
63+
------------------
64+
65+
From the root directory, unit tests can be ran with the following command:
66+
67+
```bash
68+
vendor/bin/phpunit test/phpunit --coverage-clover test/phpunit/_coverage --whitelist src
69+
```

composer.json

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,16 @@
33
"description": "PHP client library to implement Authwave in your application",
44

55
"require": {
6-
"php": ">=7.4",
6+
"php": ">=8.1",
77
"ext-openssl": "*",
8+
"phpgt/cipher": "^1.0",
89
"phpgt/http": "1.*",
9-
"phpgt/session": ">=1.1"
10+
"phpgt/session": ">=1.1",
11+
"phpgt/logger": "^1.0"
1012
},
1113
"require-dev": {
12-
"phpunit/phpunit": "8.*"
14+
"phpunit/phpunit": "8.*",
15+
"ext-sodium": "*"
1316
},
1417
"autoload": {
1518
"psr-4": {
@@ -21,4 +24,4 @@
2124
"Authwave\\Test\\": "./test/phpunit"
2225
}
2326
}
24-
}
27+
}

0 commit comments

Comments
 (0)