2017-01-11 4 views
0

JIRA (Atlassian.com)에 로그인해야하는 작은 유틸리티 응용 프로그램을 만들려고합니다.로컬 호스트의 IIS를 통해 ASP.NET/C#에서 Atlassian JIRA에 연결

우리의 JIRA 서버는 Atlassian - example.atlassian.net에서 호스팅되며 개발하려는 응용 프로그램은 IIS의 로컬 서버 (192.168.1.XXX)에서 호스팅됩니다. 이 응용 프로그램은 ASP.NET/C#을 사용합니다.

사용자가 JIRA 자격증 명을 입력해야하는 간단한 로그인 페이지를 제공하는 샘플 JIRA 예제를 실행하려고했습니다. 이 시점까지는 모든 것이 잘됩니다. 누군가가 잘못된 사용자 이름/암호를 입력하면

는 응용 프로그램 (I 깨진 것으로 판단) 일부 오류 메시지가 표시됩니다

The remote server returned an error: (401) Unauthorized. 

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: System.Net.WebException: The remote server returned an error: (401) Unauthorized. 

Source Error: 

An unhandled exception was generated during the execution of the current web request. Information regarding the origin and location of the exception can be identified using the exception stack trace below. 

Stack Trace: 


[WebException: The remote server returned an error: (401) Unauthorized.] 
    System.Net.HttpWebRequest.GetResponse() +1743 
    JiraExample.JiraManager.RunQuery(JiraResource resource, String argument, String data, String method) +597 
    JiraExample.JiraManager.GetProjects() +100 
    JiraExample.Login.Button1_Click(Object sender, EventArgs e) +143 
    System.Web.UI.WebControls.Button.OnClick(EventArgs e) +11802193 
    System.Web.UI.WebControls.Button.RaisePostBackEvent(String eventArgument) +150 
    System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1735 

그러나 올바른 사용자 이름/암호를 입력하는 경우, 그것은이 사이트에 도달 할 수 없습니다 "라는 "라고 말하며 방화벽/프록시 문제를 지적합니다.

FQDN이 없거나 사설 IP 주소가 원인입니까? 그렇다면 JIRA 응답을 내 애플리케이션으로 전달할 수있는 방법이 있습니까?

감사

편집 :

이 예

기본 인증을 사용하고 있습니다 :

HttpWebRequest request = WebRequest.Create(url) as HttpWebRequest; 
    request.ContentType = "application/json"; 
    request.Method = method; 
    string base64Credentials = GetEncodedCredentials(); 
    request.Headers.Add("Authorization", "Basic " + base64Credentials); 

    private string GetEncodedCredentials() 
    { 
     string mergedCredentials = string.Format("{0}:{1}", m_Username, m_Password); 
     byte[] byteCredentials = UTF8Encoding.UTF8.GetBytes(mergedCredentials); 
     return Convert.ToBase64String(byteCredentials); 
    } 

+0

라우터를 통해 포트 443 또는 포트 80을 노출하고 공용 IP를 OAuth 호출에 제공 할 수 있습니다. 또는 내 대답에 따라 기본 인증을 사용할 수 있습니다. – HeyZiko

+0

내 질문을 업데이트하고 코드를 추가했습니다. 기본 인증 만 사용합니다. –

답변

0

이 때문에 사설 IP 주소의의 (코드 목록 부분입니다 위). 사용중인 샘플은 토큰 왕복과 관련된 OAuth를 기반으로 제작되었습니다. 이 Jira OAuth 문서를 참조하십시오. 간단하게 유지하려면 username:password의 base64 인코딩으로 basic authentication을 사용하고 Authorization 헤더에 접두사 (기본)를 추가하십시오.

var encodedAuth = System.Convert.ToBase64String(
    System.Text.Encoding.UTF8.GetBytes("username:password") 
); 
var Client = new HttpClient(); 
Client.DefaultRequestHeaders.Add("Authorization", "Basic " + encodedAuth);