66use Aacotroneo \Saml2 \Saml2Auth ;
77use Illuminate \Routing \Controller ;
88use Illuminate \Http \Request ;
9- use OneLogin \Saml2 \Auth as OneLogin_Saml2_Auth ;
10- use URL ;
119
1210class Saml2Controller extends Controller
1311{
14-
15- protected $ saml2Auth ;
16-
17- protected $ idp ;
18-
1912 /**
20- */
21- function __construct (){
22- $ idpName = request ()->route ('idpName ' );
23- if (!in_array ($ idpName , config ('saml2_settings.idpNames ' ))) {
24- abort (404 );
25- }
26-
27- $ this ->idp = $ idpName ;
28- $ auth = Saml2Auth::loadOneLoginAuthFromIpdConfig ($ this ->idp );
29- $ this ->saml2Auth = new Saml2Auth ($ auth );
30- }
31-
32- /**
33- * Generate local sp metadata
13+ * Generate local sp metadata.
14+ *
15+ * @param Saml2Auth $saml2Auth
3416 * @return \Illuminate\Http\Response
3517 */
36- public function metadata ()
18+ public function metadata (Saml2Auth $ saml2Auth )
3719 {
38-
39- $ metadata = $ this ->saml2Auth ->getMetadata ();
20+ $ metadata = $ saml2Auth ->getMetadata ();
4021
4122 return response ($ metadata , 200 , ['Content-Type ' => 'text/xml ' ]);
4223 }
4324
4425 /**
4526 * Process an incoming saml2 assertion request.
46- * Fires 'Saml2LoginEvent' event if a valid user is Found
27+ * Fires 'Saml2LoginEvent' event if a valid user is found.
28+ *
29+ * @param Saml2Auth $saml2Auth
30+ * @param $idpName
31+ * @return \Illuminate\Http\Response
4732 */
48- public function acs ()
33+ public function acs (Saml2Auth $ saml2Auth , $ idpName )
4934 {
50- $ errors = $ this -> saml2Auth ->acs ();
35+ $ errors = $ saml2Auth ->acs ();
5136
5237 if (!empty ($ errors )) {
53- logger ()->error ('Saml2 error_detail ' , ['error ' => $ this -> saml2Auth ->getLastErrorReason ()]);
54- session ()->flash ('saml2_error_detail ' , [$ this -> saml2Auth ->getLastErrorReason ()]);
38+ logger ()->error ('Saml2 error_detail ' , ['error ' => $ saml2Auth ->getLastErrorReason ()]);
39+ session ()->flash ('saml2_error_detail ' , [$ saml2Auth ->getLastErrorReason ()]);
5540
5641 logger ()->error ('Saml2 error ' , $ errors );
5742 session ()->flash ('saml2_error ' , $ errors );
5843 return redirect (config ('saml2_settings.errorRoute ' ));
5944 }
60- $ user = $ this -> saml2Auth ->getSaml2User ();
45+ $ user = $ saml2Auth ->getSaml2User ();
6146
62- event (new Saml2LoginEvent ($ this -> idp , $ user , $ this -> saml2Auth ));
47+ event (new Saml2LoginEvent ($ idpName , $ user , $ saml2Auth ));
6348
6449 $ redirectUrl = $ user ->getIntendedUrl ();
6550
@@ -74,11 +59,15 @@ public function acs()
7459 /**
7560 * Process an incoming saml2 logout request.
7661 * Fires 'Saml2LogoutEvent' event if its valid.
77- * This means the user logged out of the SSO infrastructure, you 'should' log him out locally too.
62+ * This means the user logged out of the SSO infrastructure, you 'should' log them out locally too.
63+ *
64+ * @param Saml2Auth $saml2Auth
65+ * @param $idpName
66+ * @return \Illuminate\Http\Response
7867 */
79- public function sls ()
68+ public function sls (Saml2Auth $ saml2Auth , $ idpName )
8069 {
81- $ errors = $ this -> saml2Auth ->sls ($ this -> idp , config ('saml2_settings.retrieveParametersFromServer ' ));
70+ $ errors = $ saml2Auth ->sls ($ idpName , config ('saml2_settings.retrieveParametersFromServer ' ));
8271 if (!empty ($ errors )) {
8372 logger ()->error ('Saml2 error ' , $ errors );
8473 session ()->flash ('saml2_error ' , $ errors );
@@ -89,23 +78,27 @@ public function sls()
8978 }
9079
9180 /**
92- * This initiates a logout request across all the SSO infrastructure.
81+ * Initiate a logout request across all the SSO infrastructure.
82+ *
83+ * @param Saml2Auth $saml2Auth
84+ * @param Request $request
9385 */
94- public function logout (Request $ request )
86+ public function logout (Saml2Auth $ saml2Auth , Request $ request )
9587 {
9688 $ returnTo = $ request ->query ('returnTo ' );
9789 $ sessionIndex = $ request ->query ('sessionIndex ' );
9890 $ nameId = $ request ->query ('nameId ' );
99- $ this -> saml2Auth ->logout ($ returnTo , $ nameId , $ sessionIndex ); //will actually end up in the sls endpoint
91+ $ saml2Auth ->logout ($ returnTo , $ nameId , $ sessionIndex ); //will actually end up in the sls endpoint
10092 //does not return
10193 }
10294
103-
10495 /**
105- * This initiates a login request
96+ * Initiate a login request.
97+ *
98+ * @param Saml2Auth $saml2Auth
10699 */
107- public function login ()
100+ public function login (Saml2Auth $ saml2Auth )
108101 {
109- $ this -> saml2Auth ->login (config ('saml2_settings.loginRoute ' ));
102+ $ saml2Auth ->login (config ('saml2_settings.loginRoute ' ));
110103 }
111104}
0 commit comments