카테고리 없음2017. 10. 25. 23:46
만약 AWS SDK가 잘 작동하지 않는다면 다음과 같이 적용해보자



우선 Awake함수에서 아래와같이 HttpClient를 바꾸어준다

private void Awake()
{
UnityInitializer.AttachToGameObject(this.gameObject);
Amazon.AWSConfigs.HttpClient = Amazon.AWSConfigs.HttpClientOption.UnityWebRequest;
}

그리고 Resources 폴더에 awsconfig.xml추가.


[awsconfig.xml] 파일


1
2
3
4
5
6
7
8
9
<?xml version="1.0" encoding="UTF-8"?>
 <aws correctForClockSkew="true"
      <logging
          logTo="UnityLogger"
          logResponses="Always"
          logMetrics="true"
        
          logMetricsFormat="JSON" />  
 </aws>
cs

Assets 폴더에 link.xml 추가
[link.xml] 파일

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
 
<linker>
<assembly fullname="UnityEngine">
<type fullname="UnityEngine.Networking.UnityWebRequest" preserve="all" />
<type fullname="UnityEngine.Networking.UploadHandlerRaw" preserve="all" />
<type fullname="UnityEngine.Networking.UploadHandler" preserve="all" />
<type fullname="UnityEngine.Networking.DownloadHandler" preserve="all" />
<type fullname="UnityEngine.Networking.DownloadHandlerBuffer" preserve="all" />
</assembly>
<assembly fullname="AWSSDK.Core" preserve="all"/>
<assembly fullname="AWSSDK.CognitoIdentity" preserve="all"/>
<assembly fullname="AWSSDK.CognitoSync" preserve="all"/>
<assembly fullname="AWSSDK.DynamoDBv2" preserve="all"/>
<assembly fullname="AWSSDK.Kinesis" preserve="all"/>
<assembly fullname="AWSSDK.KinesisFirehose" preserve="all"/>
<assembly fullname="AWSSDK.Lambda" preserve="all"/>
<assembly fullname="AWSSDK.MobileAnalytics" preserve="all"/>
<assembly fullname="AWSSDK.S3" preserve="all"/>
<assembly fullname="AWSSDK.SecurityToken" preserve="all"/>
<assembly fullname="AWSSDK.SimpleEmail" preserve="all"/>
<assembly fullname="AWSSDK.SimpleNotificationService" preserve="all"/>
<assembly fullname="AWSSDK.SQS" preserve="all"/>
<assembly fullname="AWSSDK.IdentityManagement" preserve="all"/>
</linker>
cs


Posted by 작업하는 을지랑

댓글을 달아 주세요

작업/Unity2017. 10. 25. 23:41

아마 이글을 찾아오기까지 수 많은 삽질이 있었을 것으로 예상한다.

삽질을 하기전에는 반드시 빈프로젝트를 만들어 그곳에서 빌드를 하며 테스트를 하기 바란다.


Unity3D 2017.2 버젼

AWS 플러그인 aws-sdk-unity_3.3.179.0

google play service 플러그인  Google Play Game Plugin  0.938a 


우선 구글 플레이 서비스를 이용할 수 있도록

구글 데브 콘솔에서 알파 버젼을 등록해둔다.

그리고 플레이서비스에 연결해두고 출시는 하지않는다.





앞으로 구글 API 콘솔로 가야할경우 저기에 API Project 있는 링크를 타고가는것이 좋다

물론 API Project는 자동생성된이름으로 연결된 구글 API Project의 이름이다.


작업 순서

http://docs.aws.amazon.com/cognito/latest/developerguide/google.html 를 본다


이부분 이다.


Set Up Google

To enable Google+ Sign-in for your web application, you will need to create a Google Developers console project for your application.


Google+ 사용 설정이 되어있야한다. 보통 자동으로 생성되면 자동으로 사용됨으로 

  1. Go to the Google Developers console and create a new project.  (패스 자동으로 설정됨)

  2. Under APIs and auth > APIs > Social APIs, enable the Google+ API.   (패스)

  3. Under APIs and auth > Credentials > OAuth consent screen, create the dialog that will be shown to users when your app requests access to their private data.

  4. For Unity, you need to create a total of three IDs: two for Android and one for iOS. Under Credentials > Add Credentials:

    • Android: Create an OAuth 2.0 client ID for Android and an OAuth 2.0 client ID for a web application.

    • iOS: Create an OAuth 2.0 client ID for iOS.

  5. Under Credentials > Add Credentials, create a Service Account. The console will alert you that a new public/private key has been created.



4번이 중요하다


안드로이드의 경우 2개의 ID가 필요한데 하나는 안드로이드 용 키이고  (keytool 로 사인키를  SHA-1 해쉬값을 뽑아 연결한것) 

하나는 웹어플리케이션 키이다.


웹어플리케이션키는 AWS Cognito 와 연결할떄 GetIdToken을 받아와야하므로 사용되는것 같다.

이것은 구글 플러그인에서 사용되는데 


Unity 에서  Window  >Google play games > Setup > android 셋팅 쪽에가면



이화면이 보이는데 여기서 하단에보이는 Web Client ID 를 넣는부분에 위에 생성한 웹아이를 넣어준다.

구글 플레이 서비스는 이미 등록해보았을테니 패스하겠지만, 안넣었다면  구글 데브콘솔에서  업적을 하나 만들어 넣고 리소스를 받아와서 넣으면된다. 다른 사이트에 잘되있는곳 많으니 패스


그리고 이제 IAM 설정이다




Create an OpenID Provider in the IAM Console

  1. Next, you will need to create an OpenID Provider in the IAM Console. For instructions on how to set up an OpenID Provider, see Using OpenID Connect Identity Providers.

  2. When prompted for your Provider URL, enter "https://accounts.google.com".

  3. When prompted to enter a value in the Audience field, enter any one of the three client IDs your created in the previous steps.

  4. After creating the provider, click on the provider name and add two more audiences, providing the two remaining client IDs.


https://console.aws.amazon.com/iam/home?region=ap-northeast-2#/providers

요기가서 위에거 그대로 따라하면된다



글보고 따라하면 아래 그림처럼 등록된다 거기서 수정해서 Audience에 구글 API콘솔에서 만들었던 ID(웹 이랑 안드로이드) 등록한다. 위에는 IOS 까지 포함해서 3개라고 적힌것이다.








이제 나머지는 Cognito에서 등록하는것이다. 


Configure the External Provider in the Amazon Cognito Console

From the Amazon Cognito Console home page:

  1. Click the name of the identity pool for which you want to enable Amazon as an external provider. The Dashboard page for your identity pool appears.

  2. In the top-right corner of the Dashboard page, click Edit identity pool. The Edit identity pool page appears.

  3. Scroll down and click Authentication providers to expand it.

  4. Click the Google tab.

  5. Click Unlock.

  6. Enter the Google Client ID you obtained from Google, and then click Save Changes.


여기서 나느 추가적으로 아래와 같은 작업을했다.


https://ap-northeast-2.console.aws.amazon.com/cognito/federated/?region=ap-northeast-2 




구글+ 도 설정하고, OpenID 쪽에 등록하자

저 OpenID는 방금 위에서 IAM 에서 설정한 것이 여기 나오는것이다.

Audience가 여러개이므로 OpenID를 이용하는것 같다.

이러면 AWS와 Unity 쪽 설정이 끝났으므로 

Unity에서 코드로 Cognito만  설정하게하면된다.


우선 구글 플레이 Activate 부터 로그인까지


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
     var config = new PlayGamesClientConfiguration.Builder()
                .RequestIdToken()
                .Build();
        PlayGamesPlatform.InitializeInstance(config);
        PlayGamesPlatform.DebugLogEnabled = true;
        PlayGamesPlatform.Activate();
        UnityEngine.Debug.Log("Social.localUser.Authenticate");
        Social.localUser.Authenticate((bool success) => {
            UnityEngine.Debug.Log(" Social.localUser.Authenticate "+success);
            UnityEngine.Debug.Log(" Result "+success);
            if (success)
            { //이까지 오면 로그인이 되었다.

            }
            else
            {
                UnityEngine.Debug.Log("fail Authenticate");
            }
        });
cs


저 success 된 이후에 

PlayGamesPlatform.Instance.GetIdToken(); 

을 받아와야하는데 문제는 이 함수가 string을 바로 밷어내지 않을때가 있다는것이다.

나도 처음에는 빈 값을 계속 리턴해서 난감했다.

구글에서 GetIdToken을 쓰지 않기를 권장하지만, AWS SDK는 그것을 따라가지 못하고 계속 쓰고있으므로 그냥 이것을 사용하는 방식으로 구현하겠다



1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
 
    public IEnumerator LoginByGoogle()
    {
        Debug.Log("Google Login ");
        string token = PlayGamesPlatform.Instance.GetIdToken();
 
        Debug.Log("first token  " + token);
        while (string.IsNullOrEmpty(token))
        {
            token = PlayGamesPlatform.Instance.GetIdToken();
            yield return new WaitForSeconds(0.5f);
        }
        Debug.Log("token " + token);
 
        awsManager.GooglePlayLogin(token);
    }
 
cs

 

코루틴으로 토큰을 받아서

1
2
3
4
5
6
  public void GooglePlayLogin(string token)
    {
        Debug.Log("GooglePlayLogin "+token);
        Credentials.AddLogin("accounts.google.com", token);
        LoginProcess();
    }
cs


이후 나는 Login Process에서 

   Credentials.GetCredentialsAsync

와  Credentials.GetIdentityIdAsync 가 차례로 호출해서 인증받게했다


이렇게 하면 Cognito와 연동이 끝난다.


참고로 AWS SDK 에서 Unity 와 연동하면 해줘야하는 사항들이 있는데 그것을 따로 글을 남기겠다.

'작업 > Unity' 카테고리의 다른 글

Unity 에서 AWS Congito, 구글 플레이서비스와 과 연동하기  (0) 2017.10.25
Posted by 작업하는 을지랑

댓글을 달아 주세요