Page tree
Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 5 Next »

Introduction

An easy-to-use REST API, available via HTTP/HTTPS protocols GET, POST, PUT or DELETE. The requests can be used to grab site's data in simple JSON format including most of the core items.

Authentication

This APIs uses OAuth 2.0 for authentication. Consult the official OAuth2.0 documentation for the down-and-dirty technical specifications.

All resource requests (APIs Call) are requiring oauth2 authentication.

h2. Grant Types

Grant Types allow to expose multiple ways for a client to receive an Access Token. Currently supported grant types:

  1. Authorization Code: This grant type is used when the client wants to request access to protected resources on behalf of another user.
  2. Implicit: This grant type is similar to the Authorization Code grant type. But it is optimized for public clients, such as those implemented in javascript or on mobile devices, where client credentials cannot be stored.
  3. User Credentials: This grant type (a.k.a. Resource Owner Password Credentials) is used when the user has a trusted relationship with the client, and so can supply credentials directly.
  4. Client Credentials: This grant type is used when the client is requesting access to protected resources under its control (i.e. there is no third party).
  5. Refresh Token: This grant type is used to obtain additional access tokens in order to prolong the client’s authorization of a user’s resources.

Endpoints

Authorize Endpoint

Which requires the user to authenticate and redirects back to the client with an authorization code (Authorization Code grant type) or access token (Implicit grant type).

http://example.com/restful_api/authorize

h3. Token Endpoint

Which uses the configured Grant Types to return an access token to the client.

http://example.com/restful_api/token

h1. Tutorials

This project aims to create an easy-t-understand and well-tested framework for creating APIs. On this page, we will explain the basics of using phpFox RESTful API such as sending and receiving data, serializing data in HTTP requests, and more.

Get Authorization Code

Call the authorize endpoint to get the code.

http://example.com/restful__api/authorize?response_type=code&client_id=CLIENT_ID

The request above will make an authorization form to user. If the user authorize this request, an authorized code will be returned to the client's redirect URI (set in client settings).

Get Access Token

Get by Authorization Code

The authorization code can be used to receive an access token from the token endpoint.

$ curl -u CLIENT_ID:CLIENT_SECRET http://example.com/restful_api/token -d 'grant_type=authorization_code&code=AUTHORIZATION_CODE'

You will receive an access token:

Unknown macro: {"access_token"}
h3. Get implicit

Setting the query string parameter response_type=token in the authorize endpoint.

http://example.com/restful_api/authorize?response_type=token&client_id=CLIENT_ID&redirect_uri=http://app.example.com/callback

A successful token request will be returned in the fragment of the callback URI:

http://app.example.com/callback#access_token=EACCESS_TOKEN&expires_in=86400&token_type=bearer

h3. Get by User credentials

Send the user credentials directly to receive an access token

$ curl -u CLIENT_ID:CLIENT_SECRET http://example.com/restful_api/token -d 'grant_type=password&email=USER_EMAIL&password=USER_PASSWORD'

URI Parameters: email, password

h3. Get by Client credentials

Example using HTTP Basic Authentication:

$ curl -u CLIENT_ID:CLIENT_SECRET http://example.com/restful_api/token -d 'grant_type=client_credentials'

Refresh token

A refresh token must be retrieved using the Authorization Code or User Credentials grant types. This refresh token can then be used to generate a new access token of equal or lesser scope.

$ curl -u CLIENT_ID:CLIENT_SECRET http://example.com/restful_api/token -d 'grant_type=refresh_token&refresh_token=REFRESH_TOKEN'

Access resources

To access resources, you must add access token to the URI Parameters or the header of request.

http://example.com/restful_api/blog=ACCESS_TOKEN

The response data is in JSON format. Read each API for more details.

  • No labels