如何发布请求授权代码 OneDrive

本文关键字:代码 OneDrive 授权 请求 何发布 | 更新日期: 2023-09-27 18:28:58

 Uri url = new Uri("https://login.live.com/oauth20_authorize.srf");
        using (var wb = new WebClient())
        {
            var data = new NameValueCollection();
            data["client_id"] = "000000004012B29D";
            data["scope"] = "wl.signin%20wl.basic%20wl.offline_access";
            data["response_type"] = "code";
            data["redirect_uri"] = "https://login.live.com/oauth20_desktop.srf";       
            var response = wb.UploadValues(url, "POST", data);

        }

很可能认为我的后请求是错误的,但不知道为什么,我唯一怀疑的是我添加的范围,%20 是一个简单的空格,我不确定我是否可以这样写。我应该收到一个结果网址吗?但我得到的只是这个 html 代码:

"<!-- ServerInfo: BAYIDSLGN3A089 2014.10.28.00.06.35 Live1 ExclusiveNew LocVer:0 -->'r'n<!-- PreprocessInfo: BTSA007:RR1BLDA080,  -- Version: 16,0,25347,0 -->'r'n<html dir='"ltr'">'r'n    <head>'r'n        <meta http-equiv='"Content-Type'" content='"text/html; charset=utf-8'">'r'n        <base href='"https://login.live.com/pp1600/'"/>'r'n        'r'n         'r'n             't'r'n                 'r'n                                            'r'n                                    't't'r'n                            <title>Microsoft account</title>'r'n        <meta name='"PageID'" content='"i4400'">'r'n        <meta name='"SiteID'" content='"38936'">'r'n        <meta name='"ReqLC'" content='"1033'">'r'n        <meta name='"LocLC'" content='" '">'r'n        <link rel='"stylesheet'" type='"text/css'" href='"CSS/WEBblue1033.css?x=16.0.25000.0'"/>'r'n        <script type='"text/javascript'">'r'n            function EndPPCRL(rs, u) 'r'n            {'r'n                if (external) 'r'n                {'r'n                    try 'r'n                    {'r'n                        if (rs) 'r'n                        {'r'n                            external.RequestStatus = rs;'r'n                            external.WebFlowUrl = u;'r'n                            external.NotifyIdentityChanged();'r'n                            external.ReturnToApp();'r'n                        }'r'n                        else 'r'n                        {'r'n                            external._b7(); external.BrowseToAuthUI();'r'n                        }'r'n                    } 'r'n                    catch (e) { }'r'n                }'r'n            } 'r'n            function BodyLoad() 'r'n            { 'r'n                EndPPCRL(-2147186656); 'r'n            }'r'n        </script>'r'n        <script type='"text/javascript'">'r'n            WizardExternalHelper = function(){ };'r'n            WizardExternalHelper.prototype ='r'n            {'r'n                setProperty: function(key, value) 'r'n                { 'r'n                    try'r'n                    { 'r'n                        window.external.Property(key) = value;'r'n                    }'r'n                    catch (e) { }'r'n                },'r'n                finalNext: function()'r'n                { 'r'n                    try'r'n                    { 'r'n                        window.external.FinalNext();'r'n                    }'r'n                    catch (e) { }'r'n                }'r'n            };'r'n        </script>'r'n                <script type='"text/javascript'">'r'n            try 'r'n            {'r'n                var externalHelper = new WizardExternalHelper();'r'n                externalHelper.setProperty('"ExtendedErrorString'", '"'");'r'n                externalHelper.setProperty('"ErrorCode'", parseInt(1));'r'n                externalHelper.setProperty('"ErrorString'", '"This service isn't available right now—please try again later.'");'r'n                externalHelper.finalNext();'r'n            } catch (e) {};'r'n            function OnBack() {}; 'r'n            function OnNext() {};'r'n        </script>'r'n    </head>'r'n    <body class='"modern'" onLoad='"BodyLoad()'">'r'n      <div class='"header'" id='"idHeaderTD9'">'r'n        <span>Microsoft account</span>'r'n      </div>'r'n      <div class='"content'">'r'n         'r'n             't'r'n                 'r'n                                            <div style='"padding:15px 0 0 0;font-size:1px;'">&nbsp;</div>'r'n                        <h1 class='"css0046'">We're unable to complete your request</h1>'r'n                        <p class='"css0005'">Microsoft account is experiencing technical problems. Please try again later.</p>'r'n                                    't't'r'n                          </div>'r'n    </body>'r'n</html>'r'n<!-- _h-Agent: -->'r'n'r'n"

如何发布请求授权代码 OneDrive

您无法 POST 请求获取第一个代码(这看起来就是您正在做的事情(。流程如下所示:

  • 将用户发送到授权页面,他们授权您的应用程序并使用 code GET 参数重定向到您的应用程序
  • 你拿着这段代码,然后把它和一堆其他的东西一起发布Microsoft。他们用一堆OAuth令牌作为回应。
  • 现在,您可以使用这些令牌发出请求。

文档很糟糕,但看看 http://msdn.microsoft.com/en-us/library/dn659750.aspx

总结一下(这些是文档中的示例(:

  • 将用户发送到https://login.live.com/oauth20_authorize.srf?client_id=0000000603DB0F&scope=wl.signin%20wl.basic&response_type=code&redirect_uri=http%3A%2F%2Fwww.contoso.com%2Fcallback.php
  • 等待用户被定向到http://www.contoso.com/callback.php?code=2bd12503-7e88-bfe7-c5c7-82274a740ff,提取code参数
  • codeclient_idclient_secretgrant_type (authorization_code( 和redirect_uri发布到https://login.live.com/oauth20_token.srf

如果一切正常,您将获得令牌。