Exemplo n.º 1
0
 internal OAuthAccount(string id, string displayName, OAuthProvider provider, OAuthAccessToken token)
 {
     Id          = id;
     DisplayName = displayName;
     Provider    = provider;
     AccessToken = token;
 }
Exemplo n.º 2
0
        private string BuildResourceTokenUrl(string url, OAuthAccessToken token, IEnumerable <KeyValuePair <string, string> > queryParameters = null)
        {
            var parameters = new List <KeyValuePair <string, string> >(Definition.ResourceQueryParameters);

            if (null != queryParameters)
            {
                parameters.AddRange(queryParameters);
            }

            if (Definition.TokenType == TokenType.Url)
            {
                parameters.Add(new KeyValuePair <string, string>(Definition.TokenRequestUrlParameter, token.Token));
            }

            return(BuildUrl(url, parameters));
        }
Exemplo n.º 3
0
        internal async Task <OAuthResponse> RefreshToken(OAuthAccessToken token)
        {
            if (!Definition.RefreshesToken)
            {
                return(OAuthResponse.WithError("NotSupported",
                                               "Provider does not support token refresh."));
            }

            return(await GetToken(Definition.TokenUrl,
                                  Definition.RefreshTokenAuthorizationHeaders,
                                  BuildRefreshTokenRequestFields(
                                      string.IsNullOrEmpty(token.RefreshToken) ?
                                      token.Token
                    :
                                      token.RefreshToken)));
        }
Exemplo n.º 4
0
        internal virtual async Task <T> GetResource <T>(string resourceUrl, OAuthAccessToken token, IEnumerable <KeyValuePair <string, string> > queryParameters = null)
            where T : class
        {
            var url = BuildResourceTokenUrl(resourceUrl, token, queryParameters);

            using (var client = new HttpClient())
            {
                var graphHeaders = ResourceHeaders(token);

                foreach (var header in graphHeaders)
                {
                    client.DefaultRequestHeaders.Add(header.Key, header.Value);
                }

                var response = await client.GetAsync(url);

                return(await ReadHttpResponse <T>(response));
            }
        }
Exemplo n.º 5
0
 internal void SetToken(OAuthAccessToken token)
 {
     AccessToken = token;
 }
Exemplo n.º 6
0
        internal async Task <AccountData> GetAccountData(OAuthAccessToken token)
        {
            var graphResponseString = await GetResource <string>(Definition.GraphUrl, token);

            return(ReadAccountData(graphResponseString));
        }
Exemplo n.º 7
0
 internal virtual IEnumerable <KeyValuePair <string, string> > ResourceHeaders(OAuthAccessToken token)
 {
     return(CustomResourceHeaders(token).Union(
                Definition.TokenType == TokenType.Url ?
                new KeyValuePair <string, string> [0]
         :
                new[] { new KeyValuePair <string, string>("Authorization", $"{Definition.BearerTokenType} {token.Token}") }));
 }
Exemplo n.º 8
0
 internal virtual IEnumerable <KeyValuePair <string, string> > CustomResourceHeaders(OAuthAccessToken token)
 {
     return(new KeyValuePair <string, string> [0]);
 }