-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add existing oauth2Token support (#32)
Some services (as Alexa skills) manage the authentication and just provide the app oauth2 token. I added the oauth2 existing token support in "generate token" process.
- Loading branch information
Showing
6 changed files
with
48 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -59,6 +59,29 @@ await sut.GenerateToken("[email protected]", "p@$$W0rd", | |
token.AccessToken.Should().Be(expectedToken.access_token); | ||
token.RefreshToken.Should().Be(expectedToken.refresh_token); | ||
token.ExpiresAt.Should().Be(token.ReceivedAt.Plus(Duration.FromSeconds(expectedToken.expires_in))); | ||
} | ||
|
||
[Fact] | ||
public void ProvideOAuth2Token_Should_Provide_Token_From_Existing() | ||
{ | ||
var expectedToken = new | ||
{ | ||
access_token = "2YotnFZFEjr1zCsicMWpAA", | ||
expires_in = 20 | ||
}; | ||
|
||
httpTest.RespondWithJson(expectedToken); | ||
|
||
var sut = new Netatmo.CredentialManager("https://api.netatmo.com/", "clientId", "clientSecret", SystemClock.Instance); | ||
|
||
sut.ProvideOAuth2Token(expectedToken.access_token); | ||
|
||
var token = sut.CredentialToken; | ||
|
||
token.Should().BeOfType<CredentialToken>(); | ||
token.AccessToken.Should().Be(expectedToken.access_token); | ||
token.RefreshToken.Should().BeNull(); | ||
token.ExpiresAt.Should().Be(token.ReceivedAt.Plus(Duration.FromSeconds(expectedToken.expires_in))); | ||
} | ||
|
||
[Fact] | ||
|
@@ -105,4 +128,4 @@ public async Task RefreshToken_Should_Refresh_Token() | |
refreshedToken.Should().NotBe(oldToken); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters