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&client_secret=${serverOauthClientSecret}&client_id=${serverOauthClientId}`;
17
18 const options = {
19 hostname: "login.xsolla.com",
20 port: 443,
21 path: "/api/oauth2/token",
22 method: "POST",
23 headers: {
24 "Content-Type": "application/x-www-form-urlencoded",
25 "Content-Length": postData.length,
26 },
27 };
28
29 return new Promise( (resolve, reject) => {
30 const req = https.request(options, (res) => {
31 if (res.statusCode !== 200) {
32 reject(
33 new functions.https.HttpsError(
34 "internal",
35 "Server token not received"
36 )
37 );
38 }
39 let body = [];
40 res.on("data", (d) => {
41 body.push(d);
42 });
43 res.on("end", () => {
44 try {
45 body = JSON.parse(Buffer.concat(body).toString());
46 } catch (e) {
47 reject(
48 new functions.https.HttpsError(
49 "internal",
50 "Malformed server token response"
51 )
52 );
53 }
54 getClientToken(context.auth.uid, body.access_token, resolve, reject);
55 });
56 });
57 req.on("error", (e) => {
58 reject(new functions.https.HttpsError(
59 "internal",
60 "Internal error while server token flow"
61 ));
62 });
63
64 req.write(postData);
65 req.end();
66 });
67});
68
69// eslint-disable-next-line require-jsdoc
70function getClientToken(userId, serverToken, resolve, reject) {
71 const postData = JSON.stringify(
72 {
73 "server_custom_id": userId,
74 }
75 );
76
77 const path =
78 `/api/users/login/server_custom_id?projectId=${loginProjectId}&publisher_project_id=${projectId}`;
79
80 const options = {
81 hostname: "login.xsolla.com",
82 port: 443,
83 path: path,
84 method: "POST",
85 headers: {
86 "Content-Type": "application/json",
87 "Content-Length": postData.length,
88 "X-Server-Authorization": serverToken,
89 },
90 };
91
92 const req = https.request(options, (res) => {
93 if (res.statusCode !== 200) {
94 reject(
95 new functions.https.HttpsError(
96 "internal",
97 "Client token not received"
98 )
99 );
100 }
101 let body = [];
102 res.on("data", (d) => {
103 body.push(d);
104 });
105 res.on("end", () => {
106 try {
107 body = JSON.parse(Buffer.concat(body).toString());
108 } catch (e) {
109 reject(
110 new functions.https.HttpsError(
111 "internal",
112 "Malformed client token response"
113 )
114 );
115 }
116 resolve({
117 "token": body.token,
118 });
119 });
120 });
121 req.on("error", (e) => {
122 reject(new functions.https.HttpsError(
123 "internal",
124 "Internal error while client token flow"
125 ));
126 });
127
128 req.write(postData);
129 req.end();
130}
- 이 예시를 따라 프로덕션 환경에 함수를 배포합니다.
- 애플리케이션에서 함수를 호출할 클라이언트 측 로직을 추가합니다.
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&client_secret=${serverOauthClientSecret}&client_id=${serverOauthClientId}`;
11
12 const serverTokenResponse = JSON.parse(
13 http.request(
14 "https://login.xsolla.com/api/oauth2/token",
15 "post",
16 getServerTokenBody,
17 "application/x-www-form-urlencoded",
18 {})
19 );
20
21 let serverToken = ""
22 if ('access_token' in serverTokenResponse) {
23 serverToken = serverTokenResponse.access_token;
24 } else {
25 return {
26 "error_message": "Server token not received"
27 }
28 }
29
30 const getUserTokenHeaders = {
31 "X-Server-Authorization": serverToken
32 }
33
34 const getUserTokenBody = JSON.stringify(
35 {
36 "server_custom_id": currentPlayerId,
37 }
38 );
39
40 const getUserTokenPath =
41 `/api/users/login/server_custom_id?projectId=${loginProjectId}&publisher_project_id=${projectId}`;
42
43 const userTokenResponse = JSON.parse(
44 http.request(
45 `https://login.xsolla.com${getUserTokenPath}`,
46 "post",
47 getUserTokenBody,
48 "application/json",
49 getUserTokenHeaders)
50 );
51
52 if ('token' in userTokenResponse) {
53 return {
54 "token": userTokenResponse.token
55 }
56 } else {
57 return {
58 "error_message": "User token not received"
59 }
60 }
61}
- 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년 10월 10일오자 또는 기타 텍스트 오류를 찾으셨나요? 텍스트를 선택하고 컨트롤+엔터를 누르세요.