1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
/** |
4
|
|
|
* Base authenticator for SilverStripe Opauth module. |
5
|
|
|
* @author Will Morgan <@willmorgan> |
6
|
|
|
* @author Dan Hensby <@dhensby> |
7
|
|
|
* @copyright Copyright (c) 2013, Better Brief LLP |
8
|
|
|
*/ |
9
|
|
|
class OpauthAuthenticator extends MemberAuthenticator { |
|
|
|
|
10
|
|
|
|
11
|
|
|
private static |
12
|
|
|
/** |
13
|
|
|
* @var Opauth Persistent Opauth instance. |
14
|
|
|
*/ |
15
|
|
|
$opauth; |
|
|
|
|
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* get_enabled_strategies |
19
|
|
|
* @return array Enabled strategies set in _config |
20
|
|
|
*/ |
21
|
|
|
public static function get_enabled_strategies() { |
22
|
|
|
$strategyConfig = self::config()->opauth_settings['Strategy']; |
23
|
|
|
return array_keys($strategyConfig); |
24
|
|
|
} |
25
|
|
|
|
26
|
|
|
/** |
27
|
|
|
* get_opauth_config |
28
|
|
|
* @param array Any extra overrides |
29
|
|
|
* @return array Config for use with Opauth |
30
|
|
|
*/ |
31
|
|
|
public static function get_opauth_config($mergeConfig = array()) { |
32
|
|
|
$config = self::config(); |
33
|
|
|
return array_merge( |
34
|
|
|
array( |
35
|
|
|
'path' => OpauthController::get_path(), |
36
|
|
|
'callback_url' => OpauthController::get_callback_path(), |
37
|
|
|
), |
38
|
|
|
$config->opauth_settings, |
39
|
|
|
$mergeConfig |
40
|
|
|
); |
41
|
|
|
} |
42
|
|
|
|
43
|
|
|
/** |
44
|
|
|
* opauth |
45
|
|
|
* @param boolean $autoRun Should Opauth auto run? Default: false |
46
|
|
|
* @return Opauth The Opauth instance. Isn't it easy to typo this as Opeth? |
47
|
|
|
*/ |
48
|
|
|
public static function opauth($autoRun = false, $config = array()) { |
49
|
|
|
if(!isset(self::$opauth)) { |
50
|
|
|
self::$opauth = new Opauth(self::get_opauth_config($config), $autoRun); |
51
|
|
|
} |
52
|
|
|
return self::$opauth; |
53
|
|
|
} |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* get_strategy_segment |
57
|
|
|
* Works around Opauth's weird URL scheme - GoogleStrategy => /google/ |
58
|
|
|
* @return string |
59
|
|
|
*/ |
60
|
|
|
public static function get_strategy_segment($strategy) { |
61
|
|
|
return preg_replace('/(strategy)$/', '', strtolower($strategy)); |
62
|
|
|
} |
63
|
|
|
|
64
|
|
|
/** |
65
|
|
|
* @return OpauthLoginForm |
66
|
|
|
*/ |
67
|
|
|
public static function get_login_form(Controller $controller) { |
68
|
|
|
return Injector::inst()->create('OpauthLoginForm', $controller, 'LoginForm'); |
69
|
|
|
} |
70
|
|
|
|
71
|
|
|
/** |
72
|
|
|
* Get the name of the authentication method |
73
|
|
|
* |
74
|
|
|
* @return string Returns the name of the authentication method. |
75
|
|
|
*/ |
76
|
|
|
public static function get_name() { |
77
|
|
|
return _t('OpauthAuthenticator.TITLE', 'Social Login'); |
78
|
|
|
} |
79
|
|
|
|
80
|
|
|
} |
81
|
|
|
|
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.