Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add proper readme and example implementation

  • Loading branch information...
commit 01215bebf56007d279006801a01ca981ddafea96 1 parent 629ff3c
Ryan McCue authored
Showing with 94 additions and 8 deletions.
  1. +60 −0 example-implementer.php
  2. +34 −0 readme.md
  3. +0 −8 readme.txt
60 example-implementer.php
View
@@ -0,0 +1,60 @@
+<?php
+
+class Rotor_Controller_Auth {
+ /**
+ * Obtain a request token
+ *
+ * Endpoint: /auth/request_token
+ */
+ public static function request_token() {
+ try {
+ $request = OAuthRequest::from_request();
+ $data = WPOAuthProvider::request_token($request);
+
+ header('Content-Type: application/x-www-form-urlencoded');
+ echo http_build_query($data, null, '&');
+ }
+ catch (OAuthException $e) {
+ throw new Exception($e->getMessage(), 401);
+ }
+ }
+
+ /**
+ * Request authorisation for the given token
+ *
+ * Endpoint: /auth/authorize
+ * @param string $oauth_token Request token
+ */
+ public static function authorize($oauth_token) {
+ try {
+ $request = OAuthRequest::from_request();
+ $url = '/auth/authorize';
+
+ $data = WPOAuthProvider::authorize($request, $url);
+
+ header('Content-Type: text/plain');
+ echo http_build_query($data, null, '&');
+ }
+ catch (OAuthException $e) {
+ throw new Exception($e->getMessage(), 401);
+ }
+ }
+
+ /**
+ * Exchange the request token for an access token
+ *
+ * Endpoint: /auth/access_token
+ */
+ public static function access_token() {
+ try {
+ $request = OAuthRequest::from_request();
+ $result = WPOAuthProvider::access_token($request);
+
+ header('Content-Type: application/x-www-form-urlencoded');
+ echo $result;
+ }
+ catch (OAuthException $e) {
+ throw new Exception($e->getMessage(), 401);
+ }
+ }
+}
34 readme.md
View
@@ -0,0 +1,34 @@
+# WordPress OAuth Provider
+This is a WordPress plugin to enable your WordPress installation to act as an
+OAuth provider. This plugin is an internal plugin, in that you need to add most
+of the relevant OAuth endpoints yourself, with only user-facing pages set up.
+
+This plugin is best used in conjunction with an API server linked into
+WordPress, enabling use of the API server via OAuth authentication.
+
+
+## Usage
+See `example-implementer.php`
+
+
+## License
+This project is licensed under the new BSD license, and is copyright 2012 Ryan
+McCue.
+
+
+## Internals
+The OAuth tokens and nonces are stored using the WordPress transient and option
+APIs, enabling easy integration with existing object caching solutions, such as
+APC and memcache.
+
+- Tokens
+ - Request tokens: Prefixed with `wpoa_rt_`, stored as transients
+ - Access tokens: Prefixed with `wpoa_at_`, stored as options
+- Nonces: Prefixed with `wpoa_n_`
+
+
+## FAQ
+
+### Why is this totally broken?
+Are you using APC with an object caching plugin? Check that it's up-to-date, as
+older versions of APC have a bug which will break this plugin.
8 readme.txt
View
@@ -1,8 +0,0 @@
-
-
-# Internals
-## Database Usage
-- Tokens
- - Request tokens: Prefixed with `wpoa_rt_`, stored as transients
- - Access tokens: Prefixed with `wpoa_at_`, stored as options
-- Nonces: Prefixed with `wpoa_n_`
Please sign in to comment.
Something went wrong with that request. Please try again.