-
Notifications
You must be signed in to change notification settings - Fork 6
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
base: master
Are you sure you want to change the base?
Conversation
PlanGrid.Api/PlanGridHttpHandler.cs
Outdated
byte[] authParamBytes = Encoding.ASCII.GetBytes(unencoded); | ||
string encodedAuthParams = Convert.ToBase64String(authParamBytes); | ||
return encodedAuthParams; | ||
if (tokenType == TokenType.Basic) |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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.
PlanGrid.Api/PlanGridHttpHandler.cs
Outdated
@@ -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); |
There was a problem hiding this comment.
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?
This change is![Reviewable](https://camo.githubusercontent.com/23b05f5fb48215c989e92cc44cf6512512d083132bd3daf689867c8d9d386888/68747470733a2f2f72657669657761626c652e696f2f7265766965775f627574746f6e2e737667)