Beispiel #1
0
        public GetToken()
        {
            if (!File.Exists(_path))
            {
                throw new FileNotFoundException("No Access Token found! set one with the cmdlet set-token");
            }

            var readToken = new ReadAccessTokenFromFile();
            var encryptedToken = readToken.ReadFile(_path);
            var decrypt = new DecryptData(encryptedToken);
            _tokenFromFile = Encoding.UTF8.GetString(decrypt.DecryptedData);

            _token = JsonConvert.DeserializeObject<RootObject>(_tokenFromFile);
        }
Beispiel #2
0
        public string GetAccessToken()
        {
            if(_token.IsExpired())
            {
                var request = new RefreshTokenRequest(Settings.Default.ClientId,GetRefreshToken());
                //encrypt the token
                byte[] unencryptedToken = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(request));
                var encrypt = new EncryptData(unencryptedToken);
                byte[] encryptedToken = encrypt.EncryptedData;

                //save the encrypted token!
                SaveAccessToken.WriteToFile(Path, encryptedToken);
                //reset the acccess token to the new 1
                _token = JsonConvert.DeserializeObject<RootObject>(Encoding.UTF8.GetString(unencryptedToken));
            }
            return _token.access_token;
        }
Beispiel #3
0
        public RootObject GetToken(TokenRequest request)
        {
            var client = new RestClientBuilder()
                .WithAcceptHeader("application/json")
                .WithContentType("application/x-www-form-urlencoded")
                .WithBody(request.ToForm())
                .WithUri(Settings.Default.HuddleAuthServer + Settings.Default.HuddleTokenEndPoint)
                .Build().Post();

            if (client.StatusCode == HttpStatusCode.BadRequest)
            {

            }

            var token = new RootObject();
            token.access_token = client.Result.access_token;
            token.expires_in = DateTime.Now.AddSeconds(client.Result.expires_in);
            token.refresh_token = client.Result.refresh_token;

            return token;
        }