Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 32 additions & 17 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,34 +3,49 @@ name: CI
on: [push]

jobs:
build:
runs-on: [ubuntu-latest]
composer:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v3

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

- uses: php-actions/composer@v1
- name: Composer
uses: php-actions/composer@v6
with:
php_version: '8.1'

- name: Archive build
run: mkdir /tmp/github-actions/ && tar -cvf /tmp/github-actions/build.tar ./

- name: Upload build for test runner
uses: actions/upload-artifact@v1
- name: Upload build archive for test runners
uses: actions/upload-artifact@v3
with:
name: build-artifact
path: ./
path: /tmp/github-actions

test:
runs-on: [ubuntu-latest]
needs: [build]
phpunit:
runs-on: ubuntu-latest
needs: [ composer ]

steps:
- uses: actions/download-artifact@v1
- uses: actions/download-artifact@v3
with:
name: build-artifact
path: ./
path: /tmp/github-actions

- uses: php-actions/phpunit@v1
- name: Extract build archive
run: tar -xvf /tmp/github-actions/build.tar ./

- name: PHP Unit tests
uses: php-actions/phpunit@v3
with:
php_version: '8.1'
php_extensions: xdebug
configuration: test/phpunit/phpunit.xml
bootstrap: vendor/autoload.php
20 changes: 17 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ To use this repository, your application must be registered to obtain a client k
Basic usage
-----------

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.
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.

```php
<?php
Expand All @@ -23,7 +23,7 @@ define("CLIENT_KEY", "1234567890abcdef");
// Authentication steps passed via the query string from the remote provider.
$auth = new Authenticator(
CLIENT_KEY,
$_SERVER["REQUEST_URI"]
$_SERVER["REQUEST_URI"],
);

// Handle authentication login/logout action via the querystring:
Expand All @@ -41,6 +41,11 @@ elseif(isset($_GET["logout"])) {
// Authentication is handled by Authwave, so you can trust "isLoggedIn"
// as a mechanism for protecting your sensitive information.
if($auth->isLoggedIn()) {
// Available methods:
// $auth->getId(); // a unique string in ULID format - use this to store in your database
// $auth->getEmail(); // the current email of the user (could change)
// $auth->getField($name); // any extra field your application is configured to take upon user signup

echo <<<HTML
<p>You are logged in as <strong>{$auth->getEmail()}</strong></p>
<p><a href="?logout">Log out</a></p>
Expand All @@ -52,4 +57,13 @@ else {
<p><a href="?login">Log in</a></p>
HTML;
}
```
```

Running unit tests
------------------

From the root directory, unit tests can be ran with the following command:

```bash
vendor/bin/phpunit test/phpunit --coverage-clover test/phpunit/_coverage --whitelist src
```
11 changes: 7 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,16 @@
"description": "PHP client library to implement Authwave in your application",

"require": {
"php": ">=7.4",
"php": ">=8.1",
"ext-openssl": "*",
"phpgt/cipher": "^1.0",
"phpgt/http": "1.*",
"phpgt/session": ">=1.1"
"phpgt/session": ">=1.1",
"phpgt/logger": "^1.0"
},
"require-dev": {
"phpunit/phpunit": "8.*"
"phpunit/phpunit": "8.*",
"ext-sodium": "*"
},
"autoload": {
"psr-4": {
Expand All @@ -21,4 +24,4 @@
"Authwave\\Test\\": "./test/phpunit"
}
}
}
}
Loading
Loading