Oauth 2.0访问令牌问题

问题描述 投票:0回答:3

我正在使用其中一个Google API并在HTTP请求者中提供了所有OAuth 2.0凭据。我需要生成访问令牌,捕获令牌并在标头中传递此访问令牌以获取输出。但是我收到错误:

表达“'Bearer'+ payload.access_token”的执行失败。

(org.mule.api.expression.ExpressionRuntimeException)。

这是生成令牌并访问令牌的正确方法吗?

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:oauth2="http://www.mulesoft.org/schema/mule/oauth2" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
	xmlns:spring="http://www.springframework.org/schema/beans" 
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/oauth2 http://www.mulesoft.org/schema/mule/oauth2/current/mule-oauth2.xsd">
    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
    <http:request-config name="HTTP_Request_Configuration" protocol="HTTPS" host="www.googleapis.com" port="443" doc:name="HTTP Request Configuration">
        <oauth2:authorization-code-grant-type clientId="client_id" clientSecret="client_secret" redirectionUrl="http://localhost:8082/callback">
            <oauth2:authorization-request authorizationUrl="https://accounts.google.com/o/oauth2/auth" localAuthorizationUrl="http://localhost:8082/login" scopes="https://www.googleapis.com/auth/admin.directory.user"/>
            <oauth2:token-request tokenUrl="https://accounts.google.com/o/oauth2/token">
                <oauth2:token-response accessToken="#[payload.access_token]"/>
            </oauth2:token-request>
        </oauth2:authorization-code-grant-type>
    </http:request-config>
    <flow name="csdfFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test"  doc:name="HTTP"/>
        <http:request config-ref="HTTP_Request_Configuration" path="/admin/directory/v1/users?domain=aabbcc.com" method="GET" doc:name="HTTP">
            <http:request-builder>
                <http:header headerName="Authorization" value="#['Bearer '+payload.access_token]"/>
            </http:request-builder>
            <http:success-status-code-validator values="0..599"/>
        </http:request>
        <logger message="#[payload]" level="INFO" doc:name="Logger"/>
    </flow>
</mule>
mule google-oauth
3个回答
0
投票

表达似乎是错误的。

试试value="Bearer #[payload.access_token]"


0
投票

您可以在标头中传递Bearer令牌,如下所示:尝试这样:


0
投票

试试这可能对你有所帮助:

 <http:header headerName="Authorization" value="Bearer
#[flowVars.accesstoken]"/>
© www.soinside.com 2019 - 2024. All rights reserved.