wp-net / WordPressPCL

This is a portable library for consuimg the WordPress REST-API in (almost) any C# application
MIT License
340 stars 130 forks source link

Auth Api Refactoring #277

Closed navjot50 closed 2 years ago

navjot50 commented 2 years ago

Refactored the Auth api to change the AuthMethod to have more descriptive auth methods of Basic and Bearer Added a new Enum JWTPlugin which give descriptive names to the Wordpress plugin by the name of the author of plugin The method signatures for Auth are same as the previous implementation of the library The default selection for the Auth method is Bearer which was previously JWT (plugin by Enrique Chavez) The default selection for the JWT plugin is Enrique Chavez auth plugin - same as the previous implementation. There is an additional property on WorpdressClient which is JWTPlugin. So, the configuration can be compared as:

//previous configuration
var client = new WordpressClient(wordpressUri) {
    AuthMethod = AuthMethod.JWT
};

//new configuration
var client = new WordpressClient(wordpressUri) {
    AuthMethod = AuthMethod.Bearer,
    JWTPlugin = JWTPlugin.JWTAuthByEnriqueChavez
}

//new configuration will default to Enrique Chavez's plugin
//this will behave as the previous configuration
var client = new WordpressClient(wordpressUri) {
    AuthMethod = AuthMethod.Bearer
}

This PR doesn't include the changes for general JWT auth plugin. I will include it in another PR because that will be an add-on rather than a refactoring.