Example #1
0
        internal Task <Result <Session> > MockAuthenticationAsync(AuthReq authReq)
        {
            var locator = AuthHelpers.GetRandomString(10);
            var secret  = AuthHelpers.GetRandomString(10);

            return(MockAuthenticationAsync(locator, secret, authReq));
        }
Example #2
0
        public Task <Result <Session> > MockAuthenticationAsync(Credentials credentials)
        {
            // credentials ??= new Credentials(AuthHelpers.GetRandomString(10), AuthHelpers.GetRandomString(10));
            credentials = credentials ?? new Credentials(AuthHelpers.GetRandomString(10), AuthHelpers.GetRandomString(10));

            var authReq = new AuthReq
            {
                App = new AppExchangeInfo {
                    Id = _appInfo.Id, Name = _appInfo.Name, Scope = _appInfo.Scope, Vendor = _appInfo.Vendor
                },
                AppContainer = true,
                Containers   = new List <ContainerPermissions>()
            };

            return(MockAuthenticationAsync(credentials.Locator, credentials.Secret, authReq));
        }
Example #3
0
        internal async Task <Result <Session> > MockAuthenticationAsync(string locator, string secret, AuthReq authReq)
        {
            Authenticator authenticator;

            try
            {
                authenticator = await Authenticator.CreateAccountAsync(locator, secret, AuthHelpers.GetRandomString(5));
            }
            catch
            {
                authenticator = await Authenticator.LoginAsync(locator, secret);
            }

            var(_, reqMsg) = await Session.EncodeAuthReqAsync(authReq);

            var ipcReq = await authenticator.DecodeIpcMessageAsync(reqMsg);

            if (!(ipcReq is AuthIpcReq authIpcReq))
            {
                return(new InvalidOperation <Session>($"Could not get {nameof(AuthIpcReq)}"));
            }

            var resMsg = await authenticator.EncodeAuthRespAsync(authIpcReq, true);

            var ipcResponse = await Session.DecodeIpcMessageAsync(resMsg);

            if (!(ipcResponse is AuthIpcMsg authResponse))
            {
                return(new InvalidOperation <Session>($"Could not get {nameof(AuthIpcMsg)}"));
            }

            authenticator.Dispose();

            var session = await Session.AppRegisteredAsync(authReq.App.Id, authResponse.AuthGranted);

            return(Result.OK(session));
        }