1: <?php
2:
3: class RESTian_Basic_Http_Auth_Provider extends RESTian_Auth_Provider_Base {
4:
5: /**
6: * @return array
7: */
8: function get_new_credentials() {
9: return array(
10: 'username' => '',
11: 'password' => '',
12: );
13: }
14:
15: /**
16: * @return array
17: */
18: function get_new_grant() {
19: return array(
20: 'authenticated' => false,
21: );
22: }
23:
24: /**
25: * @param array $credentials
26: * @return bool
27: */
28: function is_credentials( $credentials ) {
29: return ! empty( $credentials['username'] ) && ( ! empty( $credentials['password'] ) );
30: }
31:
32: /**
33: * @param array $grant
34: * @return bool
35: */
36: function is_grant( $grant ) {
37: return ! empty( $grant['authenticated'] );
38: }
39:
40: /**
41: * @param RESTian_Request $request
42: */
43: function prepare_request( $request ) {
44: $credentials = $request->get_credentials();
45: $auth = base64_encode( "{$credentials['username']}:{$credentials['password']}" );
46: $request->add_header( 'Authorization', "Basic {$auth}" );
47: }
48:
49: }
50: