예제 #1
0
        private async Task <IResponse <JwsItem> > SignWithUser(MachineReadableCode data, User credentials)
        {
            var request = new RestRequest("{Benutzername}/Sign/JWS", Method.POST, DataFormat.Json);

            request.AddUrlSegment("Benutzername", credentials.Username);

            request.AddJsonBody(new SignWithUserRequest(credentials.Password, data.GetCode()));

            var response = await _client.ExecuteAsync <SignWithUserResponse>(request);

            if (!response.IsSuccessful)
            {
                return(new Response <JwsItem>(false, null, response.StatusDescription));
            }

            return(new Response <JwsItem>(true, new JwsItem(response.Data.result), null));
        }
예제 #2
0
        private async Task <IResponse <JwsItem> > SignWithSession(MachineReadableCode data, Session credentials)
        {
            var request = new RestRequest("Session/{sessionId}/Sign/JWS", Method.POST, DataFormat.Json);

            request.AddUrlSegment("sessionId", credentials.SessionId);

            request.AddJsonBody(new SignWithSessionRequest(credentials.SessionKey, data.GetCode()));

            var response = await _client.ExecuteAsync <SignWithSessionResponse>(request);

            if (!response.IsSuccessful)
            {
                //SESSION CAN BE INACTIVE -> SIGN WITH USER/PASSWORD
                if (response.StatusCode == System.Net.HttpStatusCode.Unauthorized)
                {
                    return(await SignWithUser(data, credentials));
                }

                return(new Response <JwsItem>(false, null, response.StatusDescription));
            }

            return(new Response <JwsItem>(true, new JwsItem(response.Data.result), null));
        }