이 문서는 외부 서비스에서 DID 를 사용하여, 일반 사용자의 로그인 및 회원 정보를 처리하는 방식을, Frontend 개발자( 웹 또는 Native 앱의 경우 WebView )가 적용하는 기준으로 설명한 문서입니다.

UML diagram (2).jpg

설치 및 준비


didconnect/didconnect.min.js at main · head77x/didconnect

didconnect/didconnect.min.js.map at main · head77x/didconnect


CDN방식으로 사용:

<script src="https://did.gavrint.com/didconnect.min.js"></script>

1. DID 연결 초기화 :

JS의window객체에 선언된didconnect.init함수를 사용하며, 인자는 해당 DID 로그인을 요청할 부모window객체를 전달합니다.

그 후, 두 개의 이벤트 처리를 위한 선언이 필요합니다. didconnenct에서 DID로그인 결과를 'DIDSignInOnSuccess'이벤트와'DIDSignInOnFailure'이벤트로 전달해주므로, 관련 이벤트 리스너를 선언해줍니다.

window.didconnect.init(window);

window.addEventListener('DIDSignInOnSuccess', (returnvalue) => {
    // DID로그인 성공 후, sining 관련 값과 개인 정보 값 등이 전달됨 - 3. DreamID성공결과값 참고
});

window.addEventListener('DIDSignInOnFailure', (returnvalue) => {
    // DID로그인 취소 또는 실패 결과 반환됨
});

2. DID 호출 방법 ( *2. SSO using DID ) :

DID를 새로운 팝업창으로 열어야 하며, 이때 URL에 GET 파라메터 방식으로 signkey( 귀사의 서버에서 해당 유저가 정상적으로 로그인 과정을 거쳤는지 체크하기 위한 유니크한 string 값) 와 fromwhere( SSO를 호출하는 앱의 주소 )를 전달하면 됩니다.

let params = encodeURI('signkey='+this.signkeystring+'&fromwhere='+this.requesterHostURL);

let trying = await window.didconnect.signIn(window, params);

3. DID 성공 후 리턴된 값 :

JSON 형식으로 결과값이 전달되며, 이 중에서 userIdentity과 signature 값을 이용해서, 귀사측의 서버에서 최종 사용자의 정상적인 DID 접속여부 확인을 진행해야 합니다.

{
    protocol: 'App Version',
    result: 'OK',  // 'Failed', 'Cancel', etc will return with 'msg' for error message
    msg: 'Error message',
    userIdentity: 'User unique identify key string',
    signature: 'DID signature result',
    data: {
        realname: 'User real name',
        mobile: 'User mobile number',
        email: 'User email address',
        passport: 'User passport information',
        birthyear: 'User birth year',
        birthmonth: 'User birth month',
        birthday: 'User birth day',
        address: 'User real address',
        emergency: 'Emergency contact information'
    }
}