Hello,I want to use http collection to query the Redhat Ansible Automation Platform API.To authenticate, I first need to retrieve the cookies from this request:
[root@107501lctm collection-config]# curl -c - https://console.aap-organismes.hp.cnp.ramage/api/login/ -v
* Trying 55.245.223.47...
* TCP_NODELAY set
* Connected to console.aap-organismes.hp.cnp.ramage (55.245.223.47) port 443 (#0)
* ALPN, offering h2
* ALPN, offering http/1.1
* successfully set certificate verify locations:
* CAfile: /etc/pki/tls/certs/ca-bundle.crt
CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, ano content] (0):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, ano content] (0):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, ano content] (0):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, ano content] (0):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, ano content] (0):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN, server did not agree to a protocol
* Server certificate:
* subject: C=FR; O=CNAM; OU=180035024; CN=console.aap-organismes.hp.cnp.ramage
* start date: Apr 9 15:00:14 2024 GMT
* expire date: Apr 9 15:00:14 2027 GMT
* subjectAltName: host "console.aap-organismes.hp.cnp.ramage" matched cert's "console.aap-organismes.hp.cnp.ramage"
* issuer: C=FR; O=CNAM; OU=180035024; CN=AC CNAM SERVICES G2
* SSL certificate verify ok.
* TLSv1.3 (OUT), TLS app data, Lno content] (0):
> GET /api/login/ HTTP/1.1
> Host: console.aap-organismes.hp.cnp.ramage
> User-Agent: curl/7.61.1
> Accept: */*
>
* TLSv1.3 (IN), TLS app data, Lno content] (0):
< HTTP/1.1 200 OK
< Server: nginx
< Date: Mon, 14 Apr 2025 08:21:25 GMT
< Content-Type: text/html; charset=utf-8
< Content-Length: 5759
< Connection: keep-alive
< Expires: Mon, 14 Apr 2025 08:21:25 GMT
< Cache-Control: max-age=0, no-cache, no-store, must-revalidate, private
< Vary: Cookie, Accept-Language, Origin, Accept-Encoding
< Content-Language: en
< X-API-Total-Time: 0.808s
< X-API-Request-Id: b83b493ff6294584bfb8a20bb77921c3
< Access-Control-Expose-Headers: X-API-Request-Id
* Added cookie csrftoken="tEi4FO0UZlNvSHSXSxCpVDE3bZLcwamm" for domain console.aap-organismes.hp.cnp.ramage, path /, expire 0
< Set-Cookie: csrftoken=tEi4FO0UZlNvSHSXSxCpVDE3bZLcwamm; Path=/; SameSite=Lax; Secure
< Strict-Transport-Security: max-age=63072000
< X-Frame-Options: DENY
< X-Content-Type-Options: nosniff
< Cache-Control: no-cache, no-store, must-revalidate
< Expires: 0
< Pragma: no-cache
<
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<meta name="robots" content="NONE,NOARCHIVE" />
<title> · AWX REST API</title>
<link href="/static/media/favicon.ico?v=4.5.2" rel="shortcut icon" />
<link rel="stylesheet" type="text/css" href="/static/rest_framework/css/bootstrap.min.css" />
<link rel="stylesheet" type="text/css" href="/static/api/api.css?v=4.5.2" />
<link rel="stylesheet" type="text/css" href="/static/rest_framework/css/prettify.css"/>
<link rel="stylesheet" type="text/css" href="/static/rest_framework/css/default.css"/>
</head>
<body class="">
<div class="wrapper">
<div class="navbar navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button btn btn-primary" class="navbar-toggle collapsed" data-toggle="collapse" data-target="#navbar-collapse" aria-expanded="false">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<a class="navbar-brand" href="/api/">
<img class="logo" src="/static/media/logo-header.svg">
<span>REST API</span>
</a>
<a class="navbar-title" href="/api/login/">
<span> — </span>
</a>
</div>
<div class="collapse navbar-collapse" id="navbar-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="/api/login/?next=/api/login/" data-toggle="tooltip" data-placement="bottom" data-delay="1000" title="Log in"><span class="glyphicon glyphicon-log-in"></span>Log in</a></li>
<li><a href="//docs.ansible.com/ansible-tower/4.5.2/html/towerapi/index.html" target="_blank" data-toggle="tooltip" data-placement="bottom" data-delay="1000" title="API Guide"><span class="glyphicon glyphicon-question-sign"></span><span class="visible-xs-inline">API Guide</span></a></li>
<li><a href="/" data-toggle="tooltip" data-placement="bottom" data-delay="1000" title="Back to application"><span class="glyphicon glyphicon-circle-arrow-left"></span><span class="visible-xs-inline">Back to application</span></a></li>
<li class="hidden-xs"><a href="#" class="resize" data-toggle="tooltip" data-placement="bottom" data-delay="1000" title="Resize"><span class="glyphicon glyphicon-resize-full"></span></a></li>
</ul>
</div>
</div>
</div>
<div class="container">
<!-- Content -->
<div id="content" role="main" aria-label="content">
<div class="well" style="width: 320px; margin-left: auto; margin-right: auto">
<div class="row-fluid">
<form action="/api/login/" role="form" method="post">
<input type="hidden" name="csrfmiddlewaretoken" value="JMmUTYClen8K4U69109C9rs2Rz1j7DDA2guOoCs53yL5MrOWJnBRUUWVSoCltDPM">
<input type="hidden" name="next" value="/api/" />
<div class="clearfix control-group "
id="div_id_username">
<div class="form-group">
<label for="id_username">Username:</label>
<input type="text" name="username" maxlength="100"
autocapitalize="off"
autocorrect="off" class="form-control textinput textInput"
id="id_username" autocomplete="off" required autofocus
>
</div>
</div>
<div class="clearfix control-group "
id="div_id_password">
<div class="form-group">
<label for="id_password">Password:</label>
<input type="password" name="password" maxlength="100" autocapitalize="off"
autocorrect="off" class="form-control textinput textInput" id="id_password"
autocomplete="off" required>
</div>
</div>
<div class="form-actions-no-box">
<button type="submit" class="btn btn-primary js-tooltip" title="Log in">LOG IN</button>
</div>
</form>
</div><!-- /.row-fluid -->
</div><!-- /.well -->
</div><!-- /.content -->
</div><!-- /.container -->
</div><!-- ./wrapper -->
<div id="footer">
<div class="container">
<div class="row">
<div class="col-sm-6">
</div>
<div class="col-sm-6 footer-copyright">
Copyright © 2021 <a href="http://www.redhat.com" target="_blank">Red Hat</a>, Inc. All Rights Reserved.
</div>
</div>
</div>
</div>
<div class="hidden">
<a class="hide-description pull-right js-tooltip" href="#" title="Hide Description"><span class="glyphicon glyphicon-remove-sign"></span></a>
<a class="toggle-description js-tooltip" href="#" title="Show/Hide Description"><span class="glyphicon glyphicon-question-sign"></span></a>
</div>
<script>
window.drf = {
csrfHeaderName: "X-CSRFToken",
csrfToken: "JMmUTYClen8K4U69109C9rs2Rz1j7DDA2guOoCs53yL5MrOWJnBRUUWVSoCltDPM"
};
</script>
<script src="/static/rest_framework/js/jquery-3.5.1.min.js"></script>
<script src="/static/rest_framework/js/ajax-form.js"></script>
<script src="/static/rest_framework/js/csrf.js"></script>
<script src="/static/rest_framework/js/bootstrap.min.js"></script>
<script src="/static/rest_framework/js/prettify-min.js"></script>
<script src="/static/rest_framework/js/default.js"></script>
<script>
$(document).ready(function() {
$('form').ajaxForm();
});
</script>
<script src="/static/api/api.js?v=4.5.2"></script>
</body>
</html>
* Connection #0 to host console.aap-organismes.hp.cnp.ramage left intact
# Netscape HTTP Cookie File
# https://curl.haxx.se/docs/http-cookies.html
# This file was generated by libcurl! Edit at your own risk.
console.aap-organismes.hp.cnp.ramage FALSE / TRUE 0 csrftoken tEi4FO0UZlNvSHSXSxCpVDE3bZLcwamm
I create this file :
froot@107501lctm collection-config]# cat aap-status-infra-api.json
{
"constants": {
"protocol": "https",
"port": "443",
"loginPath": "api/login/",
"hostname": "console.aap-organismes.hp.cnp.ramage",
"cookies": "%(builtin.httpMessage.Cookies)",
"user": "",
"pwd": ""
},
"http": {
"requests": s
{
"name": "loginCokies",
"hostname": "%(constants.hostname)",
"proto": "%(constants.protocol)",
"port": "%(constants.port)",
"endpoint": "/%(constants.loginPath)",
"method": "GET",
"headers": b
"Content-Type: text/html; charset=utf-8",
"Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8"
],
"timeout": 30,
"backend": "curl",
"rtype": "xml"
}
]
},
"selection_loop": "
],
"selection": b
]
}
How i can get cookies ?
Thank
Philippe