Skip to content

Commit aedbcf0

Browse files
env IDP_PROVIDED_USER_IDENTIFIER_NAME
1 parent eef61c3 commit aedbcf0

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/SamlIdentity.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,11 @@ public static function findIdentity($id)
4343
{
4444
$attributes = Yii::$container->get('saml')->getAttributes();
4545
if(sizeof($attributes) > 0){
46-
$id = $attributes['username'][0];
46+
$id = mt_rand();
47+
$uniqueIdentifierFromIdp = getenv('IDP_PROVIDED_USER_IDENTIFIER_NAME') ? getenv('IDP_PROVIDED_USER_IDENTIFIER_NAME') : '';
48+
if($uniqueIdentifierFromIdp){
49+
$id = $attributes[$uniqueIdentifierFromIdp] && count($attributes[$uniqueIdentifierFromIdp])>0 ? $attributes[$uniqueIdentifierFromIdp][0] : $id;
50+
}
4751
return new SamlIdentity($id,$attributes);
4852
}
4953
return null;

src/_SamlController.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,12 @@ public function actionLogin(){
2222
Yii::$container->get('saml')->requireAuth();
2323
} else {
2424
$attributes = Yii::$container->get('saml')->getAttributes();
25-
$id = $attributes['username'][0];
25+
$id = mt_rand();
26+
$uniqueIdentifierFromIdp = getenv('IDP_PROVIDED_USER_IDENTIFIER_NAME') ? getenv('IDP_PROVIDED_USER_IDENTIFIER_NAME') : '';
27+
if($uniqueIdentifierFromIdp){
28+
$id = $attributes[$uniqueIdentifierFromIdp] && count($attributes[$uniqueIdentifierFromIdp])>0 ? $attributes[$uniqueIdentifierFromIdp][0] : $id;
29+
}
30+
2631
Yii::$app->user->login(new SamlIdentity($id,$attributes), 0);
2732
$this->goBack();
2833
}

0 commit comments

Comments
 (0)