如何使用WWW API获取oauth2令牌? [英] How to get oauth2 token with the WWW API?

查看:216
本文介绍了如何使用WWW API获取oauth2令牌?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发一个需要oauth2令牌进行通信的项目。后端给了我一个curl命令,但我不知道怎么把它放到Unity的WWW表单中,因为我以前没有使用http或json文件的经验。你能帮我看一下这个令牌吗?谢谢。这里卷曲代码如何:

I am working on a project that requires to oauth2 token to communicate. The backend gives me a curl command, but I have no idea how to put it into WWW form in Unity because I have no former experience with http or json file. Could you help me to access the token? Thanks. Here how the curl code looks like:

$ curl -v -u {CLIENT_ID}:{CLIENT_SECRET} https://api.domo.com/oauth/token?grant_type=client_credentials&scope= {SCOPE}

$ curl -v -u {CLIENT_ID}:{CLIENT_SECRET} "https://api.domo.com/oauth/token?grant_type=client_credentials&scope={SCOPE}"

这是一个例子:

$ curl -v -u 441e307a-b2a1-4a99-8561-174e5b153fsa: f103fc453d08bdh049edc9a1913e3f5266447a06d1d2751258c89771fbcc8087 https://api.domo.com/oauth/ token?grant_type = client_credentials& scope = data%20user

$ curl -v -u 441e307a-b2a1-4a99-8561-174e5b153fsa:f103fc453d08bdh049edc9a1913e3f5266447a06d1d2751258c89771fbcc8087 "https://api.domo.com/oauth/token?grant_type=client_credentials&scope=data%20user"

非常感谢你!

推荐答案

我使用以下方法工作:
参考 Travis的fitbit代码

I got it working using the following method: Refer to Travis's fitbit code

var plainTextBytes = System.Text.Encoding.UTF8.GetBytes(_clientID + ":" + _consumerSecret);  
var encoded = Convert.ToBase64String(plainTextBytes);  
var form = new WWWForm();  
form.AddField("client_id", _clientID);  
form.AddField("grant_type", "authorization_code");  
form.AddField("redirect_uri", WWW.UnEscapeURL(CallBackUrl));  
form.AddField("code", _returnCode);  
var headers = form.headers;  
headers["Authorization"] = "Basic " + encoded;  
_wwwRequest = new WWW("https://api.fitbit.com/oauth2/token", form.data, headers);  

与您的后端相关,看看他们使用的是哪种oauth2,您可以看到oauth2文档< a href =https://tools.ietf.org/html/rfc6749#section-4.4.2\"rel =nofollow noreferrer>这里。随意发表评论。

Relate to your backend, see what kind of oauth2 they are using, you can see the oauth2 documentation Here. Feel free to leave a comment for question.

这篇关于如何使用WWW API获取oauth2令牌?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆