2

Microsoft で何時間にもわたってその製品の API ドキュメントを台無しにして検索した後、Windows azure pack ディストリビューションで残りの API 要求を認証する方法についてはまだわかりません。主に、仮想マシンのデプロイ プロセスを自動化する API を作成したいのですが、リソースにアクセスするための認証トークンを取得する方法に関するドキュメントが見つかりません。

一部のドキュメントには ADFS の使用が記載されていますが、認証用の ADFS REST API に関するリファレンスは提供されていません。

そもそも ADFS を使いたくありません。AZURE テナントと管理インターフェイスを使用して認証したいと考えています。

結論として、誰かが REST API 認証について助けてくれるなら、それは私の一日になります。前もって感謝します。

4

2 に答える 2

-2

私はあなたと同じような仕事をしています。

        static string GetAspAuthToken(string authSiteEndPoint, string userName, string password)
    {

        var identityProviderEndpoint = new EndpointAddress(new Uri(authSiteEndPoint + "/wstrust/issue/usernamemixed"));

        var identityProviderBinding = new WS2007HttpBinding(SecurityMode.TransportWithMessageCredential);
        identityProviderBinding.Security.Message.EstablishSecurityContext = false;
        identityProviderBinding.Security.Message.ClientCredentialType = MessageCredentialType.UserName;
        identityProviderBinding.Security.Transport.ClientCredentialType = HttpClientCredentialType.None;

        var trustChannelFactory = new WSTrustChannelFactory(identityProviderBinding, identityProviderEndpoint)
        {
            TrustVersion = TrustVersion.WSTrust13,
        };
        //This line is only if we're using self-signed certs in the installation 
        trustChannelFactory.Credentials.ServiceCertificate.SslCertificateAuthentication = new X509ServiceCertificateAuthentication() { CertificateValidationMode = X509CertificateValidationMode.None };

        trustChannelFactory.Credentials.SupportInteractive = false;
        trustChannelFactory.Credentials.UserName.UserName = userName;
        trustChannelFactory.Credentials.UserName.Password = password;

        var channel = trustChannelFactory.CreateChannel();
        var rst = new RequestSecurityToken(RequestTypes.Issue)
        {
            AppliesTo = new EndpointReference("http://azureservices/TenantSite"),
            TokenType = "urn:ietf:params:oauth:token-type:jwt",
            KeyType = KeyTypes.Bearer,
        };

        RequestSecurityTokenResponse rstr = null;
        SecurityToken token = null;


        token = channel.Issue(rst, out rstr);
        var tokenString = (token as GenericXmlSecurityToken).TokenXml.InnerText;
        var jwtString = Encoding.UTF8.GetString(Convert.FromBase64String(tokenString));

        return jwtString;
    }

パラメータ「authSiteEndPoint」は、テナント認証サイトの URL です。デフォルトのポートは 30071 です。

ここでいくつかのリソースを見つけることができます: https://msdn.microsoft.com/en-us/library/dn479258.aspx

サンプルプログラム「SampleAuthApplication」があなたの疑問を解決します。

于 2016-11-23T02:05:42.877 に答える