Skip to content

Commit

Permalink
SDK w/ Sample App (#2)
Browse files Browse the repository at this point in the history
* added one commit

* added composer.lock

* added changes to sample app

* added testing

* added more documentation

* added sample app code

* added files

* added files

* added files

* added files

* added files

* added files

* added README changes

* added README changes
  • Loading branch information
gaokevin1 authored Jun 29, 2023
1 parent 4815798 commit bc18d74
Show file tree
Hide file tree
Showing 17 changed files with 5,684 additions and 3 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.env
.DS_Store
/vendor/
51 changes: 48 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,61 @@ The Descope SDK for PHP provides convenient access to Descope authentication. Yo
Install the package with `Composer`:

```
composer require descope/descope-php
```

You'll need to set up a `.env` file in the root directory with your Descope Project ID, which you can get from the [Console](https://app.descope.com/settings/project) like this:

```
DESCOPE_PROJECT_ID=<Descope Project ID>
```

## Using the SDK

## Code Samples
In order to use the SDK you will need to initialize a `DescopeSDK` object with your Descope Project ID you defined in your `.env` file, like this:

```
require 'vendor/autoload.php';
use Descope\SDK\DescopeSDK;
$descopeSDK = new DescopeSDK([
'projectId' => $_ENV['DESCOPE_PROJECT_ID']
]);
```

This SDK will easily allow you to handle Descope JWT tokens with the following built in functions:

1. `DescopeSDK->verify($sessionToken)` - will validate the JWT signature and return either **TRUE** or **FALSE**, depending on if the JWT is valid and expired
2. `DescopeSDK->getClaims($sessionToken)` - will return all of the claims from the JWT in an array format
3. `DescopeSDK->getUserDetails($refreshToken)` - will return all of the user information (email, phone, verification status, etc.) using a provided refresh token

> **Note**: To use verify() and getClaims(), you will need to pass in your session token into the function argument. To use getUserDetails() to will need to pass in your refresh token.
## Unit Testing

The PHP directory includes unit testing using PHPUnit. You can insert values for session token and refresh tokens in the `src/tests/DescopeSDKTest.php` file, and run to validate whether or not the functions are operating properly.

1. [PHP Sample App]()
To run the tests, run this command:

```
./vendor/bin/phpunit --verbose src/tests/DescopeSDKTest.php
```

## Other Code Samples

1. [PHP Sample App](https://github.com/descope/php-sdk/sample/)
2. [WordPress Plugin](https://github.com/descope-sample-apps/wordpress-plugin)

## Running the PHP Sample App

Run this command, from the root directory, to install the necessary dependencies and start the sample app:

```
php -S localhost:3000 -t sample/
```

The app should now be accessible at http://localhost:3000/ from your web browser.

## Feedback

### Contributing
Expand All @@ -35,6 +80,6 @@ We appreciate feedback and contribution to this repository!

### Raise an issue

To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/descope/passport-descope/issues).
To provide feedback or report a bug, please [raise an issue on our issue tracker](https://github.com/descope/php-sdk/issues).

This project is licensed under the MIT license. See the <a href="./LICENSE"> LICENSE</a> file for more info.</p>
17 changes: 17 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
{
"require": {
"web-token/jwt-framework": "2.2.11",
"guzzlehttp/guzzle": "^7.0",
"paragonie/constant_time_encoding": "^2.6",
"vlucas/phpdotenv": "^5.5"
},
"require-dev": {
"phpunit/phpunit": "^9",
"squizlabs/php_codesniffer": "*"
},
"autoload": {
"psr-4": {
"Descope\\SDK\\": "src/SDK/"
}
}
}
Loading

0 comments on commit bc18d74

Please sign in to comment.