PHP:如何在GET / POST调用中将Bearer Token传递给Azure API?

时间:2017-06-02 18:02:31

标签: php azure active-directory http-headers access-token

我打电话给class Type extends React.Component { constructor(props) { super(props); this.state = { type : props.type } if(__CLIENT__ && this.state.type == "ABC"){ let self = this; window.onload = function(e) { self.lazyLoad(props.type); } } } componentDidMount(){ if(this.state.type != "ABC") { this.someFunction(); } } componentWillReceiveProps(nextProps){ if(nextProps.type !== this.state.type){ if(nextProps.type != "ABC") { this.someFunction(); } this.setState({ type : nextProps.type }); } } someFunction(){ console.log(this.state.type); //some other logic as well this.someFunction1(); } lazyLoad(type) { if(type == this.state.type){ console.log("in lazyLoad"); console.log(type); console.log(this.state.type); this.someFunction1(); } } someFunction1(){ console.log("hello"); } render() { //some code logic } 并收到这样的回复:

https://login.windows.net/common/oauth2/token

我在HostGator上托管了一个网站,试图访问我在Azure上的API。

对我在Azure上托管的API进行{ "token_type": "Bearer", "scope": "Directory.Read.All User.Read", "expires_in": "3600", "ext_expires_in": "0", "resource": "https://graph.windows.net", "access_token": {{really_long_token_1}}, "refresh_token": {{really_long_token_2}}, "id_token": {{really_long_token_3}} } 调用的正确形式是什么?这就是我到目前为止所拥有的:

GET

我在拨打电话时最终收到$url = 'https://myappservice.azurewebsites.net/api/getValues'; $options = array( 'http' => array( 'header' => array( 'x-ms-version: 2017-06-02', 'Authorization: Bearer {{really_long_token_1}}' ), 'method' => 'GET' ) ); $context = stream_context_create($options); $result = file_get_contents($url, false, $context); $var_dump($result); 服务器错误。

1 个答案:

答案 0 :(得分:0)

500内部错误,表示服务器遇到意外情况,无法完成请求。

它不应该与身份验证/授权有关,请检查是否有代码可能导致此异常。或者您可以使用非常简单的代码示例替换代码,而无需任何复杂的业务逻辑,只需返回值。