title: CURL to Authenticate to a website
body: <p>I have to enable OpenID for our command line application (Django Application) For Ex: whenever the users try to access our APIs, I have to make sure that the user is Authenticated using OpenID (Microsoft/Google). I am trying to write a Shell script to access OpenID website and then store the cookie on the user's machine and whenever he tries to access second application he should be given access based on the cookie that I store on his machine.</p>
  
  <p>I am trying to use the approach mentioned <a href="https://stackoverflow.com/questions/12399087/curl-to-access-a-page-that-requires-a-login-from-a-different-page/43288852#43288852">here</a> and whenever I try to access the second url, I am getting an error "Your browser is currently set to block cookies. You need to allow cookies to use this service."</p>
  
  <p>My websites are not on a single domain, They use OpenID to authenticate.</p>
  
  <ol>
  <li>I logged into the first website and the site redirected me to OpenID
  website (Azure AD) </li>
  <li>I accessed the redirected url using curl with username and password
  successfully and stored the cookie.</li>
  <li>When I am trying to login to the second website using the below
  line, I see this error. (Since I have the cookies stored it should be able to read them and open the second website page)</li>
  </ol>
  
  <p><code>curl --cookie ./somefile https://secondwebsite.com/b</code></p>
  
  <p>Here is my complete script</p>
  
  <pre><code>#Setting redirect url in IP variable
  set IP=`curl -w "%{url_effective}\n" -I -L -s -S http://mysite1.com -o /dev/null`
  echo "Trying to Authenticate.."
  curl -L -s -S -I -k -v -i --user "username@microsoft.com" -D ./temp/cookie $IP
  echo "Authentication successful"
  #I need to check if the cookie is set or not, If it is set Authentication is successful
  
  echo "Trying to access the second url"
  #The below line is failing, When I wrote the whole content to html file, I see the error mentioned above (Your browser is currently set to block cookies. You need to allow cookies to use this service) 
  curl --cookie ./temp/cookie https://secondwebsite.com/
  </code></pre>
  
  <p><strong>To Summarize, I am stuck with 2 questions</strong></p>
  
  <ol>
  <li>Authenticating the user to second site without needing to logging in
  again</li>
  <li>Sometimes the Authentication url asks for Password from the user,
  which will be sent to users Mobile (2 Factor Authentication). Any    pointers on how to handle this case if it arises?</li>
  </ol>