Exemplo n.º 1
0
        private async Task <AngelTokenResponse> SignInTokenRequest(TokenRequestType requestType, string username, string password)
        {
            var request = CreateBasiceRequest();

            if (requestType == TokenRequestType.resource_password)
            {
                request.UserName = username;
                request.Password = password;
            }

            var response = await ClientHelper.GetTokenResponse(request, requestType);

            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// get token response
        /// </summary>
        /// <param name="request">token reqeust</param>
        /// <param name="requestType">requestType</param>
        /// <returns>AngelTokenResponse</returns>
        public static async Task <AngelTokenResponse> GetTokenResponse(AngelTokenRequest request, TokenRequestType requestType)
        {
            if (request == null)
            {
                return(null);
            }

            AngelTokenResponse      angelResposne      = null;
            TokenResponse           response           = null;
            TokenRevocationResponse revocationResponse = null;

            switch (requestType)
            {
            case TokenRequestType.client_credential:
                response = await GetClientCredentialToken(request.Map());

                angelResposne = response?.Map();
                break;

            case TokenRequestType.resource_password:
                response = await GetResourcePasswordToken(request.MapPasswordRequest());

                angelResposne = response?.Map();
                break;

            case TokenRequestType.revocation:
                revocationResponse = await ForceTokenTimeout(request.MapRevocationRequest());

                angelResposne = response?.Map();
                break;

            case TokenRequestType.refresh:
                response = await ReferenceToken(request.MapRefRequest());

                angelResposne = response?.Map();
                break;
            }

            return(angelResposne);
        }
        /// <summary>
        /// Creates the token request URL.
        /// </summary>
        /// <param name="userName">User name</param>
        /// <param name="password">password</param>
        /// <param name="expires">Number of minutes until the token will expire</param>
        /// <returns>Returns a <see cref="Uri"/>.</returns>
        private static Uri CreateTokenRequestUrl(string userName, string password, string clientId, string clientSecret, out TokenRequestType requestType, int? expires=default(int?))
        {
            requestType = GetTokenRequestType(userName, password, clientId, clientSecret);

            if (requestType == TokenRequestType.None)
            {
                throw new ArgumentNullException("None of the following parameters should be null: userName, password.", default(Exception));
            }

            // Get the requesting URL. The query string portion will be removed.
            string referrer = Regex.Match(HttpContext.Current.Request.Url.ToString(), @"[^\?]+").Value;

            string url;

            if (requestType == TokenRequestType.User)
            {
                const string _tokenUrl = "https://www.arcgis.com/sharing/generateToken?username={0}&password={1}&referer={2}&expiration={3}&f=json";
                url = string.Format(_tokenUrl, userName, password, referrer, expires.HasValue ? expires.ToString() : string.Empty);

            }
            else
            {
                const string _tokenUrl = "https://www.arcgis.com/sharing/oauth2/token?client_id={0}&grant_type=client_credentials&client_secret={1}&f=json";
                url = string.Format(_tokenUrl, clientId, clientSecret, referrer, expires.HasValue ? expires.ToString() : string.Empty);
            }

            return new Uri(url);
        }