Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Bearer tokens. #15

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

Michael-Gendotti
Copy link

@Michael-Gendotti Michael-Gendotti commented Oct 18, 2017

This change is Reviewable

byte[] authParamBytes = Encoding.ASCII.GetBytes(unencoded);
string encodedAuthParams = Convert.ToBase64String(authParamBytes);
return encodedAuthParams;
if (tokenType == TokenType.Basic)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is fine, but a switch statement might be more idiomatic for this purpose.

private RefitSettings settings;
private string version;
private int? maxRetries;

public PlanGridHttpHandler(string accessToken, RefitSettings settings, string version, int? maxRetries)
public PlanGridHttpHandler(string accessToken, RefitSettings settings, string version, int? maxRetries, TokenType tokenType = TokenType.Basic)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this will probably require some callsite changes in PlanGridApiClient:

https://github.com/plangrid/plangrid-api-net/blob/master/PlanGrid.Api/PlanGridClient.cs#L50

            var api = (AutoGeneratedIPlanGridApi)RestService.For<IPlanGridApi>(
                new HttpClient(new PlanGridHttpHandler(apiKey, settings, version, maxRetries))
                {
                    BaseAddress = new Uri(url), Timeout = TimeSpan.FromSeconds(timeout)
                },
                settings);

i.e. you'll want to surface this new type in the Create method so clients have the opportunity to override the default scheme.

@@ -42,7 +44,7 @@ public PlanGridHttpHandler(string accessToken, RefitSettings settings, string ve
request.Content = new StringContent("", Encoding.UTF8, "application/json");
}

request.Headers.Authorization = new AuthenticationHeaderValue("Basic", authenticationToken);
request.Headers.Authorization = new AuthenticationHeaderValue(this.tokenType, authenticationToken);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this won't compile? i.e. you probably need a .ToString() at the end?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants