forked from wp-net/WordPressPCL
-
Notifications
You must be signed in to change notification settings - Fork 0
Home
navjot50 edited this page Mar 22, 2022
·
11 revisions
Welcome to the WordPressPCL wiki!
WordPressPCL requires:
- Wordpress 4.7+ https://wordpress.org/
To access protected routes, there are two authentication options:
- Authentication using JSON Web Tokens (JWT) (plugin required)
- Basic Authentication using Application Passwords
Supported JWT Plugins:
- JWT Auth plugin by Enrique Chavez (for requests requiring authentication) https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/
- JWT Auth plugin by Useful Team https://wordpress.org/plugins/jwt-auth/
WordPressPCL is built on top of the new .NET Standard targeting netstandard 1.1 and 2.0 versions - therefore it should work on the following plaforms:
- .NET Framework 4.5 and newer
- .NET Core
- Universal Windows Platform (uap)
- Windows 8.0 and newer
- Windows Phone (WinRT, not Silverlight)
- Mono / Xamarin
The WordPressPCL API Wrapper is avaiable through nuget:
> Install-Package WordPressPCL
If you execute requests required authentication you must install JWT Auth plugin and configure it. You must enable Auth Headers and defune your secret key More info https://wordpress.org/plugins/jwt-authentication-for-wp-rest-api/#description
using WordPressPCL;
// Initialize
var client = new WordPressClient("http://demo.wp-api.org/wp-json/");
//Auth
client.Auth.UseBearerAuth(JWTPlugin.JWTAuthByEnriqueChavez);
await client.Auth.RequestJWTokenAsync("username", "password");
var isValidToken = await client.IsValidJWTokenAsync();
// Get All Posts
var posts = await client.Posts.GetAll();