Skip to content

Extension Method for converting an OAuth access token to a cookie, then adding it to the Hub Connection #11

Description

@dealproc

Not sure how helpful this is/will be:

    public static class HubConnectionExtensions {
        public async static void WithOAuthToken(this HubConnection connection, Uri authUri, string accessToken) {
            var cookies = new CookieContainer();
            var clientHandler = new System.Net.Http.HttpClientHandler { 
                UseCookies = true, 
                CookieContainer = cookies 
            };
            var client = new HttpClient(clientHandler) {
                BaseAddress = new Uri(connection.Url)
            };
            client.SetBearerToken(accessToken);
            var result = await client.GetAsync(authUri);
            result.EnsureSuccessStatusCode();

            connection.CookieContainer = cookies;
        }
    }

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions