跳轉至

自動登入外部網站

外部網站自動登錄 允許已經登錄外部網站(例如,Hive Community)的用戶通過 Crossplay Launcher 啟動 PC 遊戲並自動登錄—無需任何額外的登錄步驟。

基本流程和實現

透過外部網站的跨平台啟動器自動登錄遊戲 基本操作流程如下:

  1. 登入支持「遊戲外自動登入」的網站,例如 Hive Community。
  2. 完成登入後,使用 自動登入外部網站的令牌發放 API 發放令牌。
  3. 在已登入的網站上點擊 運行遊戲,使用 Crossplay Launcher 啟動 PC 遊戲。
  4. 通過在 PC 上運行的 crossplay launcher 將第 2 步發放的令牌傳送到遊戲中。
  5. 在遊戲中執行自動登入。

根據上述操作流程,遊戲開發者可以通過以下兩個步驟實現**從外部網站自動登錄**。

  1. 使用網頁登錄API發行令牌
  2. 通過Crossplay啟動器將令牌轉移到遊戲

前置條件

在實施 透過跨平台啟動器在外部網站上自動登錄 之前,您必須準備以下內容。

  • 可以使用 Web Login API 的通信環境
  • 應用 Crossplay Launcher 的遊戲服務環境
  • SDK v4 Windows.24.4.0 或更高版本
    • 外部網站的自動登錄功能僅適用於應用 SDK Windows v4.24.0.0 或更高版本的遊戲。
Note

1. 使用網頁登錄API發行令牌

當用戶完成登錄外部網站時,開發者實現了從用戶登錄的網站自動登錄遊戲所需的令牌發放。

按照以下顺序请求提供的网络登录 API 的三个 API,并接收 web_idp_token 令牌作为响应。

  1. 呼叫登錄頁面 API 請求

    • 在請求後獲取 state 值作為響應。
  2. 驗證登錄並檢索用戶信息 API 請求

    • 在請求後獲取 enc_idp 值作為響應。
    Warning
    • 由於 enc_idp 是唯一值,請小心不要將其暴露給外部以確保安全性。(在調用 API 時,必須進行伺服器對伺服器的通信。)
  3. 從外部網站自動登錄發行令牌 API 請求

    • 請求後,作為響應發行一個 web_idp_token 令牌。
    Note
    • web_idp_token 令牌會通過跨平台啟動器傳遞給遊戲。
    • web_idp_token 令牌是一次性值,每次運行遊戲時必須重新獲取。

2. 通過跨平台啟動器將令牌傳遞給遊戲

當用戶從外部網站運行帶有跨平台啟動器的PC遊戲時,用戶已經登錄,開發者將在前一步中發出的web_idp_token編碼並傳遞給遊戲,以啟用自動登錄。

通過將令牌傳遞給遊戲來完成自動登錄的過程如下:

  1. 編碼發出的令牌
  2. 配置自動登錄的URI 包括編碼的令牌
    • 在遊戲自動安裝URI或遊戲執行URI中包含編碼的令牌
  3. 實現JavaScript代碼 包括自動登錄的URI
  4. 當用戶使用跨平台啟動器運行PC遊戲時,跨平台啟動器和遊戲執行將使用JavaScript代碼中配置的URI完成,自動登錄也將完成
Warning

如果您未登录外部网站,则无法将 web_idp_token 传递给游戏执行 URI,因此不会执行自动登录。

關於上述過程,請參考使用跨平台啟動器進行遊戲服務的實施指南。

配置自動登錄的 URI

自動登錄的 URI 是通過在先前獲得的 URI 中包含編碼的令牌來配置的,具體取決於用戶的 PC 上是否安裝了 Crossplay Launcher。

如果未安裝跨平台啟動器

遊戲自動安裝URI中包含編碼的令牌。

如果用户在未安装Crossplay的情况下点击Crossplay Launcher安装程序的下载按钮,实施的JavaScript代码将把**游戏自动安装URI**复制到用户的PC剪贴板上,已安装的Crossplay Launcher将搜索**游戏自动安装URI**以在PC上安装和运行游戏。因此,如果未安装Crossplay Launcher,您必须在Crossplay Launcher将要搜索的**游戏自动安装URI**中包含编码的令牌。

有關如何在未安裝跨平台啟動器時實施的更多信息,請參閱跨平台啟動器實施指南

這裡是一個**遊戲自動安裝 URI**的範例,帶有編碼的令牌:

hivelauncher:?app_id={AppID encoding result of the logged-in game}&start_point=9&web_idp_token={web_idp_toekn encoding result} {The entire left URI is sha1 encrypted}

# Example
hivelauncher:?app_id=com.com2us.hivesdk.windows.microsoftstore.global.normal&start_point=9&web_idp_token=eb5605514b44d7ae07f93d3921f202d0a7810eda8c343e42877b23a8a2bb5675462ae3f44c95ec59b0bdaa2ff8b28c4a971acd9439e98ef29f1c7204c230f782 9e93d5396ce59f5eaf3c3ee24a1ccda3e008364b

如果已安裝跨平台啟動器

遊戲啟動 URI中包含編碼的令牌。

如果用户在安装了跨平台启动器的情况下点击“启动游戏”按钮,跨平台启动器将在使用您之前实现的JavaScript代码启动**游戏启动URI**后自动安装并启动游戏。因此,如果安装了跨平台启动器,您必须在**游戏启动URI**中包含编码的令牌,以便立即安装和启动游戏。

有關如何在安裝跨平台啟動器時實施的更多信息,請參閱跨平台啟動器實施指南

這裡是一個**遊戲啟動 URI**的範例,包含編碼的令牌:

hivelauncher:?app_id={Encoded AppID of the logged-in game}&start_point=9&web_idp_token={Encoded web_idp_toekn}

# Example
hivelauncher:?app_id=com.com2us.hivesdk.windows.microsoftstore.global.normal&start_point=9&web_idp_token=8549cd7cf3ae7d8cab788abbb3bbf4c2306e38b7d442f02214b492c98f1c05bfff7466a64ad1a3704c962d1aec0268874830eac11455c0c562aed3c0c3505a1f

跨平台遊戲啟動器執行 Javascript 代碼實現

在「跨平台啟動器執行 Javascript 代碼」中,跨平台啟動器和遊戲是使用上述配置的 URI 執行的。此時,由網頁登錄 API 發出的 web_idp_token 令牌被傳遞給遊戲,因此可以完成使用跨平台啟動器執行的遊戲的自動登錄。

跨平台遊戲啟動器執行 Javascript 代碼實現 例子如下。

     // Set the AppID of the logged-in game.
     var appid = "로그인한 게임의 AppId 세팀함";
     // When installing the launcher, set the URI for running the game.
     var url_play_game = "hivelauncher:?app_id=" + encodeURIComponent(appid) + "&start_point=9";

     // When not installing the launcher, set the URI to copy to the clipboard.
     var url_play_clipbord = "hivelauncher:?app_id=" + encodeURIComponent(appid) + "&start_point=9";

     // Implement the API call logic separately to obtain web_idp_token.
     // At this time, call the internal path with ajax and call the API on the server side. (Required for security)
     // Information about the API can be found in the API call under “1. Issuing tokens using the web login API” above.
         // Set the web_idp_token value obtained as a result of the API call.
     var web_idp_token = "API를 통해 획득 한 토큰 값 세팅함";

     // Apply the web_idp_token to the URI when it is successfully obtained.
     if(web_idp_token != ""){
          // When the launcher is installed, add the token value for automatic login to the URI for running the game.
          url_play_game += ("&web_idp_token=" + encodeURIComponent(web_idp_token));

          // When the launcher is not installed, add the token value for automatic login to the URI to be copied to the clipboard.
          url_play_clipbord += ("&web_idp_token=" + encodeURIComponent(web_idp_token));
          // Separately implement and apply the sha1 encryption function with a space.
          url_play_clipbord += (" " + sha1(url_play_clipbord));
     }

     // Information on this function can be found in the “Implementation Guide for Serving Games with Crossplay Launcher” above.
     window.customProtocolCheck(
          url_play_game, // Pass the URI for running the game set above.
          function (e) {
               // Add processing when Crossplay Launcher execution fails.

               // ex. This is an example of necessary actions.
               // Separately implement and apply the function to copy to the clipboard.
               copyClipboard(url_play_clipbord);.
          },
          function (e) {
               // Add any necessary actions when Crossplay Launcher execution succeeds.
          },
          2500, function (e) {
               // Add processing when there is no response for more than 2500ms after Crossplay Launcher execution request.
     );

有關實現和運行Javascript代碼的更多信息,請參閱Crossplay啟動器實現指南