OpenId via Curl

♀尐吖头ヾ 提交于 2019-12-03 08:04:25

问题


How can I do OpenId based authentication using Curl? At first place can I do it? Regards, Allahbaksh


回答1:


I suppose you are talking about the curl command line, not the library. I have not tried, but according to what I know of OpenID and curl, it should be possible. However, not fully automated. You'll have to "parse" the content of the identity provider and of the content provider login pages if you want to be realy restful and generic. If you know where you're going and don't mind to couple your service and client (no hateoas), you can first authenticate with the identity provider, e.g.:

curl -iSsL --user-agent 'Mozilla/5.0' --cookie cookies --cookie-jar  cookies \
       --data login=$mylogin \
       --data passwd=$mypasswd \
       https://identprovider.example.com/login

and then post your OpenID to the content provider:

curl -iSsL --user-agent 'Mozilla/5.0' --cookie cookies --cookie-jar  cookies \
              --data openid="$myopenidurl" \
              http://contentprovider.example.com/login

This suppose that the content provider is already authorised to use the identity provider. Then get your content:

curl -iSsL --user-agent 'Mozilla/5.0' --cookie cookies --cookie-jar  cookies \
              http://contentprovider.example.com/interesting/content

Note that this approach is not restful, since I hard encoded the POST uris and fields in the code. To decouple the client and the server, the uris and field names must be extracted from responses. In a bash script, you can use sed for example.

I think is should work, but if not, then you'll have to realy follow the redirects and extract URIs and forms, since some params can be passed in the redirect URIs or in hidden form fields.



来源:https://stackoverflow.com/questions/5462950/openid-via-curl

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!