Coder Social home page Coder Social logo

vuzereus / okta-php-core-rest-api-example Goto Github PK

View Code? Open in Web Editor NEW

This project forked from oktadev/okta-php-core-rest-api-example

0.0 1.0 0.0 27 KB

Home Page: https://developer.okta.com/blog/2019/03/08/simple-rest-api-php

License: Apache License 2.0

PHP 100.00%

okta-php-core-rest-api-example's Introduction

Build a Simple REST API in PHP

This example shows how to build a simple REST API in core PHP and secure it with Okta using OAuth 2.0 Client Credentials Flow.

Please read https://developer.okta.com/blog/2019/03/08/simple-rest-api-php to see how this application was built.

Prerequisites: PHP, Composer, MySQL, Okta developer account

Okta has Authentication and User Management APIs that reduce development time with instant-on, scalable user infrastructure. Okta's intuitive API and expert support make it easy for developers to authenticate, manage, and secure users and roles in any application.

Getting Started

Sign up for an Okta developer account and create a new application. Make note of the Client ID and Issuer values for your application.

Clone this project using the following commands:

[email protected]:oktadeveloper/okta-php-core-rest-api-example.git
cd okta-php-core-rest-api-example

Configure the application

Create the database and user for the project:

mysql -uroot -p
CREATE DATABASE api_example CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;
CREATE USER 'api_user'@'localhost' identified by 'api_password';
GRANT ALL on api_example.* to 'api_user'@'localhost';
quit

Copy and edit the .env file and enter your database details and Okta details there:

cp .env.example .env

Install the project dependencies and start the PHP server:

composer install
cd public
php -S 127.0.0.1:8000

Loading 127.0.0.1:8000/person should return a 401 Unauthorized response now.

NOTE: if using a virtual machine and NAT, you might need to run the server as php -S 0.0.0.0:8000 -t public instead.

Run the client application

In the public directory, simply run:

php client.php

If you see 'Obtaining token...success!' on the first line then Okta authentication is working correctly. After that, you should see the client app execute some API requests and dump the output.

Help

Please post any questions as comments on the

, or visit our Okta Developer Forums. You can also email [email protected] if would like to create a support ticket.

License

Apache 2.0, see LICENSE.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.