none
How to authenticate with R Server in a c# app as local admin and how to get service specific swagger.json? RRS feed

  • Question

  • I am trying to consume a service in a c# app as local admin. I created the client library for the core api from the swagger file showed in this post: https://msdn.microsoft.com/en-us/microsoft-r/operationalize/app-developer-get-started . But I faced the problem that i am unable to authenticate with the r server as I always get a timeout. I am also unable to get the service specific swagger.json  The following code shows my attempt, but the debugging always stops at var loginResponse in the login Task :

    class Program
        {
            // --- CREATE API CLIENT -------------------------------------------------------------
            static DeployRClient client = new DeployRClient(new Uri("serverip"));
            static void Main(string[] args)
            {
    
                var auth = Login();
                var createSessionResponse = client.CreateSession(
                new CreateSessionRequest("Session One"));
    
                Console.WriteLine("Session ID: " + createSessionResponse.SessionId);
    
            }
    
    
    
            async static Task Login()
            {
                // Authenticate using username/password
                var loginRequest = new LoginRequest("username", "password");
                var loginResponse = await client.LoginAsync(loginRequest);
    
                // Set Authorization header with `Bearer` and access-token
                var headers = client.HttpClient.DefaultRequestHeaders;
                var accessToken = loginResponse.AccessToken;
    
                headers.Remove("Authorization");
                headers.Add("Authorization", $"Bearer {accessToken}");
            }
        }
    Furthermore i am able to execute remote commands on the R server in my R script. Thanks for the help!



    • Edited by Stev93 Wednesday, January 18, 2017 3:25 PM more specific text
    Wednesday, January 18, 2017 3:24 PM

All replies