2016-03-11 52 views
0

我正在將我的CRM應用程序集成到Yammer,因爲我在Yammer內創建了一個應用程序,並且使用ClientID,客戶端密鑰和重定向URL來驗證Yammer用戶的身份。使用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; 
        } 

回答

0

我只是不希望這個如有用戶登錄使用我的應用程序 到Yammer的,應該允許自動

這是設計,不能從你的代碼中改變/繞過。必須向用戶提供允許或拒絕使用yammer第三方應用程序的選項。

如果它適合您的用例,您可以考慮使用模擬端點 - https://developer.yammer.com/docs/impersonation