gpt4 book ai didi

PHP 头文件问题

转载 作者:行者123 更新时间:2023-12-03 19:13:07 24 4
gpt4 key购买 nike

好的,所以我需要使用 PHP header 重定向到带有 appID 的网站,并在其末尾进行重定向。
这是我到目前为止。

我给老师发了电子邮件,这是他给我的信息:

“对于第一个,您将 header 定向到 OAuth 端点( http://oauth.jseis.me/auth/token )并在 URL 末尾设置 app_id 和重定向 URL”

//The user want to log in
if(isset($_GET["action"]) && $_GET["action"] == "login")
{
$newURL = 'http://oauth.jseis.me/auth/token'.$app_id.'/'.$redirect;
//TODO: Redirect to the token endpoint with the app_id and redirect in the URL
header('Location: '.$newURL);
}

当我这样做时,我应该在网站的 URL 中获得一个 token ,它会将我带到这个 http://oauth.jseis.me/auth/token22e5d9ca9d4a1d84769c0291166e0caf/http://elliotwyllie.com/index.php这只是重复我发送的原因,但我的老师告诉我它应该退还给我一个我可以使用的 token 。

到目前为止,这里是我的全部代码供引用:
<?

session_start();


/*

For this assignment the grant token endpoint is:

https://oauth.jseis.me/auth/token

and the access token endpoint is:

https://oauth.jseis.me/auth/access

*/


//TODO: Fill these in using the information from
//the user page at https://oauth.jseis.me

$app_id = "22e5d9ca9d4a1d84769c0291166e0caf";
$redirect = "http://elliotwyllie.com/index.php";

//The server has redirected back to here with a token in the URL
if(isset($_GET["token"]))
{

$token = $_GET["token"];

//TODO: Send a POST request with the token to the access_token endpoint
//Save the access token you get back as $_SESSION["access_token"]
//The response will be in JSON format so you'll need to learn about json_decode()

}

//The user want to log in
if(isset($_GET["action"]) && $_GET["action"] == "login")
{
$newURL = 'http://oauth.jseis.me/auth/token'.$app_id.'?redirect='.$redirect;
//TODO: Redirect to the token endpoint with the app_id and redirect in the URL
header('Location: '.$newURL);
}

//The user wants to log out
else if(isset($_GET["action"]) && $_GET["action"] == "logout")
{
session_destroy();
header("Location: index.php");
}

?>
<html>
<head>
<meta charset="UTF-8">
<title>CSCI 3000 - oAuth 2.0 Example</title>

<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css" integrity="sha384-Vkoo8x4CGsO3+Hhxv8T/Q5PaXtkKtu6ug5TOeNV6gBiFeWPGFN9MuhOf23Q9Ifjh" crossorigin="anonymous">

<script src="https://code.jquery.com/jquery-3.4.1.slim.min.js" integrity="sha384-J6qa4849blE2+poT4WnyKhv5vZF5SrPo0iEjwBvKU7imGFAV0wwj1yYfoRSJoZ+n" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js" integrity="sha384-wfSDF2E50Y2D1uUdj0O3uMBJnjuUD4Ih7YwaYd1iqfktj0Uod8GCExl3Og8ifwB6" crossorigin="anonymous"></script>

<style tyle="text/css">

body,html
{
margin:0px;
padding:0px;
background-color:#EEE;
font-family: Arial, Helvetica, sans-serif;
font-size:12px;
}

#container
{
margin:100px auto;
width:800px;
background-color:#FFF;
border:1px solid #AAA;
padding:20px;
}

label
{
display:inline-block;
width:150px;
font-weight:bold;
}

</style>

</head>
<body>
<div id="container">
<?

if(isset($_SESSION["access_token"]))
{
?><div style='text-align:right'>
<a href="index.php?action=logout">Log Out</a>
</div><?
$ch = curl_init();
curl_setopt($ch,CURLOPT_URL, "https://oauth.jseis.me/api/userinfo");
curl_setopt($ch,CURLOPT_HTTPHEADER,array("Token: ".$_SESSION["access_token"]));
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true);
$userinfo = curl_exec($ch);
curl_close($ch);

echo "<p>Here's what I found out about this user from the remote service:</p><p style='font-weight:bold;'>".$userinfo."</p>";
}

else
{
?>You are not currently logged in. <a href="index.php?action=login">Click here</a> to authenticate with OAuth 2.0<?
}

?>
</div>
</body>
</html>

有人要求说明,所以他们来了!
Part 1 – IDP Setup
In order for the Service Provider script on your own website to be able to log in
correctly, it needs to establish a trust with my Identity Provider.
Register and log in to https://oauth.jseis.me/ and it will provide you with the information
that you need to configure your script. You’ll need to input the address of your script for
the redirect URL (Something like http://yoursite.com/A4/index.php)
You can also fill in some information here that is your “Private information” that only
authenticated websites should be able to read.


Part 2 – SP Setup
Create a folder called “A4” on your server and make a new index.php file inside it. Copy
this script and paste it into the new file. Complete each of the three areas of the script
that are marked “TODO”. If you do it correctly, then you should be able to browse to that
page and click the log in button. You’ll be directed to my website where you will be able
to log in using the same account you registered before. Next, your script will perform the
OAuth flow detailed above and you’ll be logged in on your own website.
The interesting thing here is that now you’ll see the “secret information” you put into my
website on your own website. It is being retrieved directly from the remote server using
the access token to verify who you are.
The fun part about this is that now any student in the class can also browse to your
website and log in and see their own secret information. But your website never needs
to ask them for their username or password. It simply asks mine, and believes they are
who I saw they are. Cool eh?

最佳答案

你得到了绝对可悲的指示。

我在您的 OAuth 提供商处注册了一个帐户,正如您所说,没有提供有关使用哪个 URL 的说明,但经过一些反复试验,我发现您需要提供 app_id 查询字符串 范围。例如

$newUrl = 'http://oauth.jseis.me/auth/token?' . http_build_query([
'app_id' => $app_id
]);

我没有找到在请求中设置重定向 URL 的任何方法。

这似乎与您的帐户相关联,但在您注册时

idp

我试过
  • redirect
  • redirect_url
  • redirect_uri

  • 但返回 URL 始终是针对该帐户注册的 URL。

    关于PHP 头文件问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/61492034/

    24 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com