Skip to content

Commit

Permalink
Merge pull request #59 from kuzzleio/1.0.3-proposal
Browse files Browse the repository at this point in the history
# [1.0.3](https://github.com/kuzzleio/sdk-csharp/releases/tag/1.0.3) (2020-09-18)


#### Bug fixes

- [ [#58](#58) ] Fix expiresIn option handling   ([scottinet](https://github.com/scottinet))

---
  • Loading branch information
scottinet committed Sep 18, 2020
2 parents f4374fa + 24da1e7 commit a027799
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
26 changes: 18 additions & 8 deletions Kuzzle.Tests/API/Controllers/AuthControllerTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -192,13 +192,18 @@ public class AuthControllerTest {
credentials,
expiresIn);

_api.Verify(new JObject {
var expectedQuery = new JObject {
{ "controller", "auth" },
{ "action", "login" },
{ "strategy", "foostrategy" },
{ "expiresIn", expiresIn?.TotalMilliseconds },
{ "body", credentials }
});
{ "body", credentials },
};

if (expiresIn != null) {
expectedQuery["expiresIn"] = $"{Math.Floor((double)expiresIn?.TotalSeconds)}s";
}

_api.Verify(expectedQuery);

Assert.Equal<JObject>(
expected,
Expand Down Expand Up @@ -250,11 +255,16 @@ public class AuthControllerTest {

JObject result = await _authController.RefreshTokenAsync(expiresIn);

_api.Verify(new JObject {
var expectedQuery = new JObject {
{ "controller", "auth" },
{ "action", "refreshToken" },
{ "expiresIn", expiresIn?.TotalMilliseconds }
});
};

if (expiresIn != null) {
expectedQuery["expiresIn"] = $"{Math.Floor((double)expiresIn?.TotalSeconds)}s";
}

_api.Verify(expectedQuery);

Assert.Equal<JObject>(
expected,
Expand Down Expand Up @@ -338,4 +348,4 @@ public class AuthControllerTest {
Assert.Equal(value, result);
}
}
}
}
24 changes: 18 additions & 6 deletions Kuzzle/API/Controllers/AuthController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -144,13 +144,19 @@ JObject credentials
JObject credentials,
TimeSpan? expiresIn = null
) {
Response response = await api.QueryAsync(new JObject {
var query = new JObject {
{ "controller", "auth" },
{ "action", "login" },
{ "strategy", strategy },
{ "body", credentials },
{ "expiresIn", expiresIn?.TotalMilliseconds }
});
};

if (expiresIn != null) {
// workaround to https://github.com/kuzzleio/kuzzle/issues/1784
query["expiresIn"] = $"{Math.Floor((double)expiresIn?.TotalSeconds)}s";
}

Response response = await api.QueryAsync(query);

api.AuthenticationToken = (string)response.Result["jwt"];

Expand All @@ -176,11 +182,17 @@ JObject credentials
/// Refreshes an authentication token.
/// </summary>
public async Task<JObject> RefreshTokenAsync(TimeSpan? expiresIn = null) {
Response response = await api.QueryAsync(new JObject {
var query = new JObject {
{ "controller", "auth" },
{ "action", "refreshToken" },
{ "expiresIn", expiresIn?.TotalMilliseconds }
});
};

if (expiresIn != null) {
// workaround to https://github.com/kuzzleio/kuzzle/issues/1784
query["expiresIn"] = $"{Math.Floor((double)expiresIn?.TotalSeconds)}s";
}

Response response = await api.QueryAsync(query);

api.AuthenticationToken = (string)response.Result["jwt"];

Expand Down
2 changes: 1 addition & 1 deletion Kuzzle/Kuzzle.nuspec
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<metadata>
<id>kuzzlesdk</id>
<title>Kuzzle SDK</title>
<version>1.0.2</version>
<version>1.0.3</version>
<authors>Kuzzle Team</authors>
<owners>Kuzzle Team</owners>
<license type="expression">Apache-2.0</license>
Expand Down

0 comments on commit a027799

Please sign in to comment.