使用yammer进行身份验证

时间:2016-03-11 07:03:21

标签: rest yammer office365-restapi

我正在将我的CRM应用程序集成到Yammer,因为我已经在Yammer内创建了一个应用程序,并使用ClientID,Client Secret和重定向URL我正在对应用程序的Yammer用户进行身份验证。

问题是,每当用户更改密码或任何其他尝试通过应用程序登录的用户时,都会要求允许或不允许。我只是不想要这个如果任何用户通过使用我的应用程序登录到yammer它应该自动允许。请帮我解决这个问题,我也发布了我的代码

referalUrl = oauthUrl + clientId;
            oauthUrl =oauthUrl+ clientId + "&redirect_uri=" + redirUrl;      //For authentication to Yammer
            //referalUrl = oauthUrl + clientId;
            accessTokenUrl = accessTokenUrl + "client_id=" + clientId + "&client_secret=" + clientSecret + "&code=";
            string qsCode = string.Empty;
            string accessToken = "";
            string postResults = string.Empty;
            string response = string.Empty;
            string firstName = string.Empty;
            string lastName = string.Empty;
            //string currentUser = string.Empty;
            object yammerUserId = this.PrimaryDataRow[YammerUserTable.Field.YammerUserId];
            object currentUserId = this.SystemClient.UserProfile.EmployeeId;


        if (string.IsNullOrEmpty(accessToken))
        {
            while (string.IsNullOrEmpty(qsCode))
            {
                response = YammerAPIRequest.MakeGetRequest(oauthUrl, null, true);

                //look for authenticity token
                string authToken = YammerAPIRequest.GetAuthenticityToken(response);

                if (!string.IsNullOrEmpty(authToken))
                {
                    string f = System.Web.HttpUtility.UrlEncode(authToken);

                    userName = System.Web.HttpUtility.UrlEncode(userName);
                    //password = System.Web.HttpUtility.UrlEncode(password);
                    string postBody = "utf8=%E2%9C%93&authenticity_token=" + System.Web.HttpUtility.UrlEncode(authToken) + "&network_permalink=aptean.com&login=" +
                        userName + "&password=" + password + "&remember_me=on";

                    postResults = YammerAPIRequest.MakeLoginPostRequest(postBody, loginUrl, f, null, referalUrl);
                }
                qsCode = postResults;
                if (qsCode.IndexOf("code") == -1 && qsCode.IndexOf("redirect_uri")==-1)
                {
                    PivotalMessageBox.Show("Please enter Correct Username or Password");
                    return false;
                }
                else
                {
                    PivotalMessageBox.Show("You have Logged in to Yammer");
                    string postreq = "utf8=%E2%9C%93&authenticity_token=" + System.Web.HttpUtility.UrlEncode(authToken) + "&allow=Allow";
                    string allowurl="https://www.yammer.com/aptean.com/oauth2/decision?client_id=BAUC8GdiEZ5ximkabWM9Q&redirect_uri=https%3A%2F%2Fwww.yammer.com%2Faptean.com%2F&response_type=code";
                    string allow = YammerAPIRequest.AllowtoApp(postreq, allowurl, authToken, null, null);
                    if (allow != "")
                    {
                        qsCode = allow;
                    }

1 个答案:

答案 0 :(得分:0)

  

如果有任何用户使用我的应用登录yammer,我只是不想要这个   它应该自动允许

这是设计使然,不能更改/绕过您的代码。必须为用户提供允许或拒绝使用yammer第三方应用程序的选项。

您可以考虑使用模拟端点,如果它适合您的用例 - https://developer.yammer.com/docs/impersonation