PlayEveryWare / eos_plugin_for_unity

Repository for PlayEveryWare's EOS Plugin for Unity, bringing the functionality of Epic Online Services to the Unity Game Engine.
https://eospluginforunity.playeveryware.com
287 stars 56 forks source link

Unable to authenticate using a non-developer account #53

Closed Zammstein closed 2 years ago

Zammstein commented 2 years ago

Brand settings for my title have been approved and it works when testing it with a dev account.

My implementation code:

    public override void RequestPlatformID(Action<GetPlatformIDResult, string> callback) {
        LoginToEpic(LoginCredentialType.PersistentAuth, callback);
    }

    private void LoginToEpic(LoginCredentialType loginType, Action<GetPlatformIDResult, string> callback) {
        Credentials credentials = new Credentials {
            Type = loginType,
        };

        EOSManager.Instance.StartLoginWithLoginOptions(new LoginOptions {
            Credentials = credentials,
        }, (loginCallback => {
            if (loginCallback.ResultCode == Result.Success) {
                EOSManager.Instance.StartConnectLoginWithEpicAccount(loginCallback.LocalUserId, (connectLoginCallback) => {
                    if (connectLoginCallback.ResultCode == Result.Success) {
                        callback?.Invoke(GetPlatformIDResult.Success, loginCallback.LocalUserId.ToString());
                    } else {
                        callback?.Invoke(GetPlatformIDResult.Failed, string.Empty);
                    }
                });
            } else if (loginType == LoginCredentialType.PersistentAuth) {
                LoginToEpic(LoginCredentialType.AccountPortal, callback);
            } else {
                Debug.LogErrorFormat(DEBUG + "StartLoginWithLoginOptions ResultCode ({0})", loginCallback.ResultCode);
                callback?.Invoke(GetPlatformIDResult.Failed, string.Empty);
            }
        }));
    }

After the first attempt with LoginCredentialType.PersistentAuth type I receive:

StartLoginWithLoginTypeAndToken No existing persistent auth credentials were found for automatic login. StartLoginWithLoginTypeAndToken Record Event: EOSSDK.HTTP.Complete ClientAuthTask Success NewClientToken: Client ClientId: xyz...Q4q Access[Expires: 2022.03.07-17.55.03 Remaining: 7200.16] State: Valid xyz...Q4q result: eyJ...tEQ Record Event: EOSSDK.HTTP.Complete FInitiateDeviceFlowTask Success Device code flow to be continued at https://www.epicgames.com/activate?userCode=SBBBXRCY Launching platform browser for account portal Error response received from backend. ServiceName=[OAuth], OperationName=[TokenGrant], Url=[], HttpStatus=[400], ErrorCode=[errors.com.epicgames.account.oauth.authorization_pending], NumericErrorCode=[1012], ErrorMessage=[The authorization server request is still pending as the end user has yet to visit and enter the verification code.], CorrId=[EOS-pyw0sNfd5UWuSovo4XQHbw-AGx03vOpPUeES-1I9aPaRw-lm5oeVy1Z0-jrk6t2lz35Q] Polling for token grant. Device code flow to be continued at https://www.epicgames.com/activate?userCode=SBBBXRCY Record Event: EOSSDK.HTTP.Complete Next token grant poll Error response received from backend. ServiceName=[OAuth], OperationName=[TokenGrant], Url=[], HttpStatus=[400], ErrorCode=[errors.com.epicgames.account.oauth.authorization_pending], NumericErrorCode=[1012], ErrorMessage=[The authorization server request is still pending as the end user has yet to visit and enter the verification code.], CorrId=[EOS-pyw0sNfd5UWuSovo4XQHbw-AGx03vOpPUeES-1I9aPaRw-MUidY1YDd0GBQRZjwD-o2w] Polling for token grant. Device code flow to be continued at https://www.epicgames.com/activate?userCode=SBBBXRCY Record Event: EOSSDK.HTTP.Complete Next token grant poll Error response received from backend. ServiceName=[OAuth], OperationName=[TokenGrant], Url=[], HttpStatus=[400], ErrorCode=[errors.com.epicgames.account.oauth.authorization_pending], NumericErrorCode=[1012], ErrorMessage=[The authorization server request is still pending as the end user has yet to visit and enter the verification code.], CorrId=[EOS-pyw0sNfd5UWuSovo4XQHbw-AGx03vOpPUeES-1I9aPaRw-LlWQFplxs0ig_BymbFMPog] Polling for token grant. Device code flow to be continued at https://www.epicgames.com/activate?userCode=SBBBXRCY Record Event: EOSSDK.HTTP.Complete Next token grant poll FPollTokenGrantRequestTask Success Record Event: EOSSDK.HTTP.Complete FInitiateDeviceFlowTask Complete Success NewUserToken: User ClientId: xyz...Q4q AccountId: 741...62b Access[Expires: 2022.03.07-17.55.33 Remaining: 7199.99] Refresh[Expires: 2022-09-03T15:55:33.991Z Remaining: 15551999.99] State: Valid GenerateUserAuth success Persistent auth credentials successfully updated in the local keychain. Record Event: EOSSDK.HTTP.Complete login/queryuserinfo success Social Overlay: 'leaderboards' feature disabled by overlay. Login Tasks Complete: 0 Social Overlay: Loading: Social Overlay: Initital DisplaySettings{ Visible(FALSE) ExclusiveInput(FALSE) HitBox(unset) } Overlay loading in instance 1917771513040 Record Event: Overlay.ClientApi.LoadURL LoadURL result received. [Success=1, BrowserID=1] Record Event: Overlay.RenderProcess.LoadURL Record Event: Overlay.MessageHandler.LoadURLResult Record Event: Overlay.RenderProcess.BrowserCreated Record Event: Overlay.RenderProcess.ConnectBrowserAndRenderProcesses Record Event: Overlay.MessageHandler.BrowserStatus Error response received from backend. ServiceName=[EOSAuth], OperationName=[TokenGrant], Url=[], HttpStatus=[404], ErrorCode=[errors.com.epicgames.eos.auth.user_not_found], NumericErrorCode=[110016], ErrorMessage=[EOS User Identity not found. identityProviderId: epicgames accountId: 741a35744182426ab699e358368d762b], CorrId=[EOS-pyw0sNfd5UWuSovo4XQHbw-AGx03vOpPUeES-1I9aPaRw--n3OtYpTt061CmpNmE0E8g] Record Event: EOSSDK.HTTP.Complete [EPIC_USER_PROVIDER] : StartConnectLoginWithEpicAccount ResultCode (InvalidUser)`

After the InvalidUser result I try again using LoginCredentialType.AccountPortal and get the same InvalidUser result:

Error response received from backend. ServiceName=[EOSAuth], OperationName=[TokenGrant], Url=[], HttpStatus=[404], ErrorCode=[errors.com.epicgames.eos.auth.user_not_found], NumericErrorCode=[110016], ErrorMessage=[EOS User Identity not found. identityProviderId: epicgames accountId: 741a35744182426ab699e358368d762b], CorrId=[EOS-pyw0sNfd5UWuSovo4XQHbw-AGx03vOpPUeES-1I9aPaRw--n3OtYpTt061CmpNmE0E8g] Record Event: EOSSDK.HTTP.Complete [EPIC_USER_PROVIDER] : StartConnectLoginWithEpicAccount ResultCode (InvalidUser)

KesKim commented 2 years ago

Just sorting out my own auth/API issues looking through these posts, but I have a guess - maybe your non-dev account doesn't own the game on Epic Store, therefore doesn't have the access to it and is an Invalid User?

Zammstein commented 2 years ago

The problem was me not understanding the authentication flow. I got it working:

public void RequestPlatformID(Action<GetPlatformIDResult, string> callback) {
    LoginToEpic(LoginCredentialType.PersistentAuth, callback);
}

private void LoginToEpic(LoginCredentialType loginType, Action<GetPlatformIDResult, string> callback) {
    Credentials credentials = new Credentials {
        Type = loginType,
    };

    EOSManager.Instance.StartLoginWithLoginOptions(new LoginOptions {
        Credentials = credentials,
        ScopeFlags = AuthScopeFlags.BasicProfile | AuthScopeFlags.FriendsList | AuthScopeFlags.Presence,
    }, (loginCallback => {
        if (loginCallback.ResultCode == Result.Success) {
            callback?.Invoke(GetPlatformIDResult.Success, loginCallback.LocalUserId.ToString());

            Token tolkien = EOSManager.Instance.GetUserAuthTokenForAccountId(loginCallback.LocalUserId);

            Epic.OnlineServices.Connect.LoginOptions options = new Epic.OnlineServices.Connect.LoginOptions {
                Credentials = new Epic.OnlineServices.Connect.Credentials {
                    Token = tolkien.AccessToken,
                    Type = ExternalCredentialType.Epic,
                },
            };

            EOSManager.Instance.StartConnectLoginWithOptions(options, (connectLoginCallback) => {
                if (connectLoginCallback.ResultCode == Result.Success) {
                    callback?.Invoke(GetPlatformIDResult.Success, loginCallback.LocalUserId.ToString());
                } else if (connectLoginCallback.ResultCode == Result.InvalidUser) {
                    EOSManager.Instance.CreateConnectUserWithContinuanceToken(connectLoginCallback.ContinuanceToken, (onCreateConnectUserCallback) => {
                        if (onCreateConnectUserCallback.ResultCode == Result.Success) {
                            callback?.Invoke(GetPlatformIDResult.Success, loginCallback.LocalUserId.ToString());
                        } else {
                            Debug.LogErrorFormat(DEBUG + "CreateConnectUserWithContinuanceToken ResultCode ({0})", onCreateConnectUserCallback.ResultCode);
                            callback?.Invoke(GetPlatformIDResult.Failed, string.Empty);
                        }
                    });
                } else {
                    Debug.LogErrorFormat(DEBUG + "StartConnectLoginWithEpicAccount ResultCode ({0})", connectLoginCallback.ResultCode);
                    callback?.Invoke(GetPlatformIDResult.Failed, string.Empty);
                }
            });
        } else if (loginType == LoginCredentialType.PersistentAuth) {
            LoginToEpic(LoginCredentialType.AccountPortal, callback);
        } else {
            Debug.LogErrorFormat(DEBUG + "StartLoginWithLoginOptions ResultCode ({0})", loginCallback.ResultCode);
            callback?.Invoke(GetPlatformIDResult.Failed, string.Empty);
        }
    }));
}