ecphp / cas-bundle

CAS Bundle, a standard Symfony bundle for authentication using CAS protocol.
https://ecphp-cas-bundle.readthedocs.io
BSD 3-Clause "New" or "Revised" License
43 stars 9 forks source link

Normalize CAS Attributes #93

Closed smbpunt closed 11 months ago

smbpunt commented 11 months ago

Hello @drupol ,

I noticed that you have released a new major version of the bundle, so I wanted to see if the modifications could be easily integrated into our applications.

After a few tweaks (because we're overriding some of your bundle's functionalities), it seems to work.

I have a small question regarding the attributes returned by CAS.

The table returned doesn't seem "normalized".

Example of attributes with version ^2.5:

[
  "mail" => "toto.toto@toto.fr",
  "displayName" => "Toto TOTO",
  // ...
]

Attributes with version ^3.0 :

[
  "mail" => [
     0 => "toto.toto@toto.fr"
  ],
  "displayName" => [
     0 => "Toto TOTO"
  ],
  // ...
]

Is there a method, such as passing a parameter to the login function, to normalize attributes? I could certainly extend my User class or modify the constructor, but I wonder if the CAS library could handle this normalization internally?

Thanks

drupol commented 11 months ago

Hello!

Thanks for opening the issue.

I guess you're talking about the new version ^3? Are you using CAS with XML or JSON ? I guess you're using XML but I may be wrong.

If you're using XML, this is indeed the default behaviour now since we've updated the library that parses it (https://github.com/ecphp/cas-lib/blob/master/src/Utils/Response.php).

I don't like saying that but if you want to use this version, I guess you'll have to follow the upgrade path and update your own code.

smbpunt commented 11 months ago

Yes, I am referring to version ^3.

I've identified the problem. Upon using version ^3, I encountered an error with xml_decode. I switched to JSON, which worked well, aside from the issue with attribute normalization.

After reverting to XML, I found I needed to explicitly require veewee/xml in my Symfony application, which resulted in the attributes being formatted as they were in version ^2.5/XML. However, I am puzzled as to why veewee/xml was not automatically installed, given that it is listed as a dependency.

drupol commented 11 months ago

So, your problem is solved? Glad to hear it :)

After reverting to XML, I found I needed to explicitly require veewee/xml in my Symfony application, which resulted in the attributes being formatted as they were in version ^2.5/XML. However, I am puzzled as to why veewee/xml was not automatically installed, given that it is listed as a dependency.

There are at least 3 reasons why it is in require-dev instead of require. I list it in the suggestions, but I don't install it by default, because:

  1. It requires the PHP extension xsl which might not be available by default
  2. The xsl extension doesn't work on Windows machine (CI is currently broken because of that)
  3. If you don't use XML in CAS, there's no need to have that dependency

Let me know if I can be more helpful, if not, feel free to close the issue.

Thanks!

smbpunt commented 11 months ago

Ok, thanks for clarifying everything.

And thank you for the quick feedback, as always.