Yammer Authentication in C # Console Application

I am using the NuGet Yammer API, and I am trying to simply authenticate and display the token as a test.

Unfortunately, I cannot get it to work. I'm new to this, but there is no NuGet Yammer API documentation, and this will be a console application. All the examples and documentation on the Yammer developers page show this using a web application.

My code is:

static void Main(string[] args)
{
    var myConfig = new ClientConfigurationContainer
    {

        ClientCode = null,
        ClientId = "CODEHERE",
        ClientSecret = "CODEHERE"
    };
    var myYammer = new YammerClient(myConfig);
    var test = myYammer.GetToken();
    Console.WriteLine("Token" + test);
    Console.ReadLine();
}
+4
source share
2 answers

This is OAuth Authentication , you must interact with the Yammer OAuth webpage to receive a token.

You should look at the asp.net mvc example in CodePlex sources .

In HomeController.cs:

[HttpPost]
public ActionResult Index(IndexViewModel model)
{
    if (ModelState.IsValid)
    {
        var myConfig = new ClientConfigurationContainer
        {
            ClientCode = null,
            ClientId = model.ClientId,
            ClientSecret = model.ClientSecret,
            RedirectUri = Request.Url.AbsoluteUri + Url.Action("AuthCode")
        };

        var myYammer = new YammerClient(myConfig);

        // Obtain the URL of Yammer Authorisation Page
        var url = myYammer.GetLoginLinkUri();

        this.TempData["YammerConfig"] = myConfig;

        // Jump to the url page
        return Redirect(url);
    }
    return View(model);
}

Yammer :

public ActionResult AuthCode(String code)
{
    if (!String.IsNullOrWhiteSpace(code))
    {
        var myConfig = this.TempData["YammerConfig"] as ClientConfigurationContainer;
        myConfig.ClientCode = code;
        var myYammer = new YammerClient(myConfig);
        // var yammerToken = myYammer.GetToken();
        // var l = myYammer.GetUsers();
        // var t= myYammer.GetImpersonateTokens();
        // var i = myYammer.SendInvitation("test@test.fr");
        // var m = myYammer.PostMessage("A test from here", 0, "Event");
        return View(myYammer.GetUserInfo());
    }
    return null;
}
+3

Source: https://habr.com/ru/post/1525404/


All Articles