튜토리얼
튜토리얼
.NET Core 개발환경에서 바로써트 SDK를 추가하여 본인인증 요청(requestIdentity) 함수를 구현하는 예시입니다.
1. BaroCert SDK 추가
[프로젝트 > NuGet 패키지 관리] 메뉴에서 barocert 검색하여 최신 버전의 패키지를 설치합니다.
2. BaroCert SDK 설정
						① 프로젝트의 Startup.cs 파일에 카카오써트 서비스 인스턴스 클래스를 생성하고, Startup클래스의 ConfigureServices() 함수에 의존성 주입 패턴으로 Singleton 서비스 인스턴스를 추가합니다.
						② 카카오써트 서비스명으로 컨트롤러를 생성하고 생성한 컨트롤러의 생성자 함수에서 카카오써트 인스턴스 객체를 할당합니다.
					
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Barocert.kakaocert;
using Microsoft.AspNetCore.Routing;
public class KakaocertInstance
{
	// 링크아이디
	private string linkID = "TESTER";
	
	// 비밀키
	private string secretKey = "SwWxqU+0TErBXy/9TVjIPEnI0VTUMMSQZtJf3Ed8q3I=";
	public KakaocertService kakaocertService;
	public KakaocertInstance()
	{
		// Kakaocert 서비스 객체 초기화
		kakaocertService = new KakaocertService(linkID, secretKey);
		// 인증토큰 IP 검증 설정, ture-사용, false-미사용, (기본값:true)
		kakaocertService.IPRestrictOnOff = true;
		// 통신 고정 IP, true-사용, false-미사용, (기본값:false)
		kakaocertService.UseStaticIP = false;
	}
}
namespace BarocertExample
{
	public class Startup
	{
		public Startup(IConfiguration configuration)
		{
			Configuration = configuration;
		}
		public IConfiguration Configuration { get; }
		// This method gets called by the runtime. Use this method to add services to the container.
		public void ConfigureServices(IServiceCollection services)
		{
			// Add framework services.
			services.AddMvc();
			services.AddSingleton<KakaocertInstance>();
		}
		// This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
		public void Configure(IApplicationBuilder app, IHostingEnvironment env)
		{
			if (env.IsDevelopment())
			{
				app.UseDeveloperExceptionPage();
			}
			else
			{
				app.UseExceptionHandler("/Home/Error");
			}
			app.UseStaticFiles();
			app.UseMvc(routes =>
			{
				routes.MapRoute(
					name: "default",
					template: "{controller=Kakaocert}/{action=Index}");
			});
		}
	}
}
				3. RequestIdentity 기능 구현
카카오써트 서비스명으로 생성한 컨트롤러의 생성자 함수에 인스턴스 객체를 할당하고, RequestIdentity 함수 코드를 추가합니다.
/*
* 카카오톡 이용자에게 본인인증을 요청합니다.
* https://developers.barocert.com/reference/kakao/dotnetcore/identity/api#RequestIdentity
*/
public IActionResult RequestIdentity()
{
	// 이용기관코드 (파트너 사이트에서 확인가능)
	String clientCode = "023040000001";
	// 본인인증 요청 정보 객체
	Identity identity = new Identity();
	// 수신자 휴대폰번호 - 11자 (하이픈 제외)
	identity.receiverHP = _kakaocertService.encrypt("01012341234");
	// 수신자 성명 - 80자
	identity.receiverName = _kakaocertService.encrypt("홍길동");
	// 수신자 생년월일 - 8자 (yyyyMMdd)
	identity.receiverBirthday = _kakaocertService.encrypt("19700101");
	// 인증요청 메시지 제목 - 최대 40자
	identity.reqTitle = "본인인증 요청 메시지 제목";
	// 커스텀 메시지 - 최대 500자
	identity.extraMessage = _kakaocertService.encrypt("본인인증 커스텀 메시지");
	// 인증요청 만료시간 - 최대 1,000(초)까지 입력 가능
	identity.expireIn = 1000;
	// 서명 원문 - 최대 40자 까지 입력가능
	identity.token = _kakaocertService.encrypt("본인인증 요청 원문");
	// AppToApp 인증요청 여부
	// true - AppToApp 인증방식, false - Talk Message 인증방식
	identity.appUseYN = false;
	try
	{
		var result = _kakaocertService.requestIdentity(clientCode, identity);
		return View("requestIdentity", result);
	}
	catch (BarocertException ke)
	{
		return View("exception", ke);
	}
}
				4. 결과 확인
함수 호출이 정상적으로 처리되면 "채널 메시지 인증" 방식은 접수아이디(32자리 숫자)가 반환되며, "앱투앱 인증" 방식은 접수아이디와 AppScheme 이 함께 반환됩니다. 실패인 경우 BarocertException으로 오류코드("-"로 시작하는 8자리 숫자값)와 오류메시지가 반환됩니다. [오류코드]