OpenId via Curl

2019-03-11 02:24发布

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

1条回答
干净又极端
2楼-- · 2019-03-11 03:14

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.

查看更多
登录 后发表回答