예제 #1
0
        public async Task <ActivityDetails> GetActivityDetailsAsync(string encryptedConnectToken, string sdkId, AsymmetricCipherKeyPair keyPair, Uri apiUrl)
        {
            Validation.NotNullOrEmpty(encryptedConnectToken, nameof(encryptedConnectToken));

            string token = CryptoEngine.DecryptToken(encryptedConnectToken, keyPair);
            string path  = $"profile/{token}";

            Request profileRequest = new RequestBuilder()
                                     .WithKeyPair(keyPair)
                                     .WithHttpMethod(HttpMethod.Get)
                                     .WithBaseUri(apiUrl)
                                     .WithEndpoint(path)
                                     .WithQueryParam("appId", sdkId)
                                     .WithHeader(Constants.Api.AuthKeyHeader, CryptoEngine.GetAuthKey(keyPair))
                                     .Build();

            using (HttpResponseMessage response = await profileRequest.Execute(_httpClient).ConfigureAwait(false))
            {
                if (!response.IsSuccessStatusCode)
                {
                    Response.CreateYotiExceptionFromStatusCode <YotiProfileException>(response);
                }

                return(ActivityDetailsParser.HandleResponse(
                           keyPair,
                           await response.Content.ReadAsStringAsync().ConfigureAwait(false)));
            }
        }
        /// <summary>
        /// Asynchronously request a <see cref="ActivityDetails"/>  using the encrypted token provided by yoti during the login process.
        /// </summary>
        /// <param name="encryptedToken">The encrypted returned by Yoti after successfully authenticating.</param>
        /// <returns>The account details of the logged in user as a <see cref="ActivityDetails"/>. </returns>
        public async Task <ActivityDetails> GetActivityDetailsAsync(string encryptedConnectToken, string sdkId, AsymmetricCipherKeyPair keyPair, string apiUrl)
        {
            string token = CryptoEngine.DecryptToken(encryptedConnectToken, keyPair);
            string path  = "profile";

            byte[]     httpContent = null;
            HttpMethod httpMethod  = HttpMethod.Get;

            string endpoint = EndpointFactory.CreateProfileEndpoint(httpMethod, path, token, sdkId);

            Dictionary <string, string> headers = CreateHeaders(keyPair, httpMethod, endpoint, httpContent, contentType: YotiConstants.ContentTypeJson);

            Response response = await _httpRequester.DoRequest(
                new HttpClient(),
                HttpMethod.Get,
                new Uri(
                    apiUrl + endpoint),
                headers,
                httpContent);

            if (response.Success)
            {
                return(_activity.HandleSuccessfulResponse(keyPair, response));
            }
            else
            {
                ActivityOutcome outcome = ActivityOutcome.Failure;
                switch (response.StatusCode)
                {
                case (int)HttpStatusCode.NotFound:
                {
                    outcome = ActivityOutcome.ProfileNotFound;
                }
                break;
                }

                return(new ActivityDetails
                {
                    Outcome = outcome
                });
            }
        }