BaaS 인증이 있는 Shop Builder 사용
인게임 아이템 판매에 Shop Builder를 BaaS 권한 부여 시스템과 함께 사용할 수 있습니다. 이 경우의 상호 작용은 다음과 같습니다.
- 사용자가 BaaS 인증 시스템을 통해 귀하의 애플리케이션에 로그인합니다.
- BaaS 서비스는 사용자 ID를 전달하여 엑솔라 서버로부터 사용자 JSON 웹 토큰(JWT)을 요청합니다.
- 엑솔라 서버는 사용자 JWT를 BaaS 서비스에 반환합니다.
- BaaS 서비스는 사용자 JWT를 애플리케이션에 전달합니다.
- 애플리케이션은 사용자 JWT를 사용하여 API를 사용하는 엑솔라 서버와 상호 작용합니다.
알림
사용자 인증용 로직을 구현하지 않은 경우 엑솔라 로그인을 통합하고 PlayFab 또는 Firebase에서 사용자 데이터의 저장소를 설정할 수 있습니다. 이를 통해 로그인 API를 사용하여 사용자를 인증하고 JWT를 수신하여 다른 엑솔라 제품의 API와 상호 작용할 수 있습니다.
- 관리자 페이지에서 표준 로그인 프로젝트를 자신의 프로젝트에 연결합니다.
- 서버 OAuth 2.0 클라이언트를 설정합니다.
- Firebase와 PlayFab용 지침에 따라 프로젝트에 미리 만들어진 함수를 추가합니다.
서버 OAuth 2.0 클라이언트 설정
- 관리자 페이지에서 프로젝트를 열고 로그인 섹션으로 이동합니다.
- 로그인 프로젝트의 패널에서 구성을 클릭합니다.
- 보안 블록으로 이동한 후 OAuth 2.0 섹션을 선택합니다.
- OAuth 2.0 추가를 클릭합니다.
- OAuth 2.0 리디렉션 URI를 지정합니다.
- 서버(서버 간 연결) 상자를 선택 표시합니다.
- 연결을 클릭합니다.
- 클라이언트 ID와 비밀 키를 복사하여 저장합니다.
클라우드 기능을 Firebase 프로젝트에 추가
- Firebase 프로젝트를 초기화합니다.
- 사용자 JWT 기능에 대한 수신 기능을 가져오고 구성합니다. 여기에서:
<ProjectID>
는 프로젝트 ID이며 프로젝트 이름 옆의 관리자 페이지에서 확인할 수 있습니다.<LoginID>
는 로그인 ID이며 로그인 > 대시보드 > 로그인 프로젝트 섹션으로 이동하고 로그인 프로젝트 이름 옆에 있는 ID 복사를 클리한 후 관리자 페이지을 열어 가져올 수 있습니다.<OAuthClientID>
는 서버 OAuth 2.0 클라이언트를 설정할 때 받은 클라이언트 ID입니다.<OAuthSecretKey>
는 서버 OAuth 2.0 클라이언트를 설정할 때 받은 비밀 키입니다.
사용자 JWT 수신용 함수 코드:
Copy
- javascript
1const projectId = "<ProjectID>";
2const loginProjectId = "<LoginID>";
3
4const serverOauthClientId = <OAuthClientID>;
5const serverOauthClientSecret = "<OAuthSecretKey>";
6
7exports.getXsollaLoginToken = functions.https.onCall((data, context) => {
8 if (!context.auth) {
9 throw new functions.https.HttpsError(
10 "failed-precondition",
11 "The function must be called while authenticated."
12 );
13 }
14
15 const postData =
16 "grant_type=client_credentials" +
17 `&client_secret=${serverOauthClientSecret}`+
18 `&client_id=${serverOauthClientId}`;
19
20 const options = {
21 hostname: "login.xsolla.com",
22 port: 443,
23 path: "/api/oauth2/token",
24 method: "POST",
25 headers: {
26 "Content-Type": "application/x-www-form-urlencoded",
27 "Content-Length": postData.length,
28 },
29 };
30
31 return new Promise( (resolve, reject) => {
32 const req = https.request(options, (res) => {
33 if (res.statusCode !== 200) {
34 reject(
35 new functions.https.HttpsError(
36 "internal",
37 "Server token not received"
38 )
39 );
40 }
41 let body = [];
42 res.on("data", (d) => {
43 body.push(d);
44 });
45 res.on("end", () => {
46 try {
47 body = JSON.parse(Buffer.concat(body).toString());
48 } catch (e) {
49 reject(
50 new functions.https.HttpsError(
51 "internal",
52 "Malformed server token response"
53 )
54 );
55 }
56 getClientToken(context.auth.uid, body.access_token, resolve, reject);
57 });
58 });
59 req.on("error", (e) => {
60 reject(new functions.https.HttpsError(
61 "internal",
62 "Internal error while server token flow"
63 ));
64 });
65
66 req.write(postData);
67 req.end();
68 });
69});
70
71// eslint-disable-next-line require-jsdoc
72function getClientToken(userId, serverToken, resolve, reject) {
73 const postData = JSON.stringify(
74 {
75 "server_custom_id": userId,
76 }
77 );
78
79 const path =
80 "/api/users/login/server_custom_id?" +
81 `projectId=${loginProjectId}&` +
82 `publisher_project_id=${projectId}`;
83
84 const options = {
85 hostname: "login.xsolla.com",
86 port: 443,
87 path: path,
88 method: "POST",
89 headers: {
90 "Content-Type": "application/json",
91 "Content-Length": postData.length,
92 "X-Server-Authorization": serverToken,
93 },
94 };
95
96 const req = https.request(options, (res) => {
97 if (res.statusCode !== 200) {
98 reject(
99 new functions.https.HttpsError(
100 "internal",
101 "Client token not received"
102 )
103 );
104 }
105 let body = [];
106 res.on("data", (d) => {
107 body.push(d);
108 });
109 res.on("end", () => {
110 try {
111 body = JSON.parse(Buffer.concat(body).toString());
112 } catch (e) {
113 reject(
114 new functions.https.HttpsError(
115 "internal",
116 "Malformed client token response"
117 )
118 );
119 }
120 resolve({
121 "token": body.token,
122 });
123 });
124 });
125 req.on("error", (e) => {
126 reject(new functions.https.HttpsError(
127 "internal",
128 "Internal error while client token flow"
129 ));
130 });
131
132 req.write(postData);
133 req.end();
134}
- 이 예시를 따라 프로덕션 환경에 함수를 배포합니다.
- 애플리케이션에서 함수를 호출할 클라이언트 측 논리를 추가합니다.
getXsollaLoginToken
을 함수 이름으로 지정합니다. 매개 변수 전달은 하지 않아도 됩니다. - 애플리케이션에서 API를 이용해 자체적으로 작업하거나 엑솔라 SDK를 이용해 작업할 메소드를 구현합니다.
클라우드 스크립트를 PlayFab 프로젝트에 추가
- 사용자 JWT 수신용 함수 코드를 사용하여 JS 파일을 생성합니다. 여기에서
<ProjectID>
는 프로젝트 ID이며 프로젝트 이름 옆의 관리자 페이지에서 확인할 수 있습니다.<LoginID>
는 로그인 ID이며 로그인 > 대시보드 > 로그인 프로젝트 섹션으로 이동하고 로그인 프로젝트 이름 옆에 있는 ID 복사를 클리한 후 관리자 페이지을 열어 가져올 수 있습니다.<OAuthClientID>
는 서버 OAuth 2.0 클라이언트를 설정할 때 받은 클라이언트 ID입니다.<OAuthSecretKey>
는 서버 OAuth 2.0 클라이언트를 설정할 때 받은 비밀 키입니다.
알림
프로젝트에서 클라우드 스크립트를 이미 사용 중인 경우 코드 끝에 사용자 JWT 수신용 함수를 추가합니다.
Copy
- javascript
1handlers.GetXsollaLoginToken = function (args) {
2
3 // TODO replace with production credentials
4 const projectId = <ProjectID>;
5 const loginProjectId = "<LoginID>";
6 const serverOauthClientId = <OAuthClientID>;
7 const serverOauthClientSecret = "<OAuthSecretKey>";
8
9 const getServerTokenBody =
10 "grant_type=client_credentials" +
11 `&client_secret=${serverOauthClientSecret}` +
12 `&client_id=${serverOauthClientId}`;
13
14 const serverTokenResponse = JSON.parse(
15 http.request(
16 "https://login.xsolla.com/api/oauth2/token",
17 "post",
18 getServerTokenBody,
19 "application/x-www-form-urlencoded",
20 {})
21 );
22
23 let serverToken = ""
24 if ('access_token' in serverTokenResponse) {
25 serverToken = serverTokenResponse.access_token;
26 } else {
27 return {
28 "error_message": "Server token not received"
29 }
30 }
31
32 const getUserTokenHeaders = {
33 "X-Server-Authorization": serverToken
34 }
35
36 const getUserTokenBody = JSON.stringify(
37 {
38 "server_custom_id": currentPlayerId,
39 }
40 );
41
42 const getUserTokenPath =
43 "/api/users/login/server_custom_id?" +
44 `projectId=${loginProjectId}&` +
45 `publisher_project_id=${projectId}`;
46
47 const userTokenResponse = JSON.parse(
48 http.request(
49 "https://login.xsolla.com" + getUserTokenPath,
50 "post",
51 getUserTokenBody,
52 "application/json",
53 getUserTokenHeaders)
54 );
55
56 if ('token' in userTokenResponse) {
57 return {
58 "token": userTokenResponse.token
59 }
60 } else {
61 return {
62 "error_message": "User token not received"
63 }
64 }
65}
- PlayFab 프로젝트 설정으로 이동합니다.
- 클라우드 스크립트 파일을 업로드합니다.
- 클라우드 스크립트를 프로덕션 환경에서 실행합니다.
- 클라이언트 측 논리를 애플리케이션에서 함수 호출에 추가합니다.
GetXsollaLoginToken
을 함수 이름으로 지정합니다. 매개 변수 전달은 하지 않아도 됩니다.
사용자 JWT 수신 함수 호출의 예시
Copy
kotlin
- kotlin
- C#
- C++
1val tokenRequest = PlayFabClientModels.ExecuteCloudScriptRequest()
2tokenRequest.FunctionName = "GetXsollaLoginToken"
3val res = PlayFabClientAPI.ExecuteCloudScript(tokenRequest)
4val result = res.Result.FunctionResult as Map<*, *>
5val token = result["token"]
6val errorMessage = result["error_message"]
1var tokenRequest = new ExecuteCloudScriptRequest{
2 FunctionName = "GetXsollaLoginToken"
3};
4
5PlayFabClientAPI.ExecuteCloudScript(
6 tokenRequest,
7 scriptResult =>
8 {
9 var functionResult = scriptResult.FunctionResult as Dictionary<string, string>;
10 var token = functionResult["token"];
11 },
12 playfabError => { Debug.LogError($"GetXsollaAccessToken error: {playfabError.ErrorMessage}"); });
1void UMyClass::GetXsollaToken()
2{
3 FClientExecuteCloudScriptRequest tokenRequest;
4 tokenRequest.FunctionName = TEXT("GGetXsollaLoginToken");
5
6 UPlayFabClientAPI::FDelegateOnSuccessExecuteCloudScript onSuccess;
7 onSuccess.BindUFunction(this, "OnTokenRecieved");
8
9 UPlayFabClientAPI::FDelegateOnFailurePlayFabError onFailure;
10 onSuccess.BindUFunction(this, "OnError");
11
12 UPlayFabClientAPI::ExecuteCloudScript(tokenRequest, onSuccess, onFailure, nullptr);
13}
14
15void UMyClass::OnTokenRecieved(FClientExecuteCloudScriptResult result, UObject* customData)
16{
17 const FString& token = result.FunctionResult->GetStringField(TEXT("token"));
18
19 // do something with a token
20}
21
22void UMyClass::OnError(FPlayFabError error, UObject* customData)
23{
24 // handle errors
25}
알림
이 예시에서는PlayFab SDK 메서드를 사용하여 클라우드 스크립트에 요청합니다. 요청과 응답 처리를 프로젝트에 PlayFab SDK를 추가하지 않고 자체적으로 하실 수 있습니다.
이 기사가 도움이 되었나요?
의견을 보내 주셔서 감사드립니다!
메시지를 검토한 후 사용자 경험 향상에 사용하겠습니다.유용한 링크
마지막 업데이트: 2025년 4월 2일오자 또는 기타 텍스트 오류를 찾으셨나요? 텍스트를 선택하고 컨트롤+엔터를 누르세요.