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

Credentials exposes expires_in if returned after auth #72

Merged
merged 2 commits into from
Dec 15, 2016

Conversation

cocojoe
Copy link
Member

@cocojoe cocojoe commented Dec 13, 2016

Tests added

context("expires_in responses") {

it("should have valid exiresIn from string") {
let credentials = Credentials(json: ["expires_in": String(expiresIn)])
Copy link
Member

Choose a reason for hiding this comment

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

use string interpolation for the value

}

convenience required public init(json: [String: Any]) {
self.init(accessToken: json["access_token"] as? String, tokenType: json["token_type"] as? String, idToken: json["id_token"] as? String, refreshToken: json["refresh_token"] as? String)
var expiresIn: Date? = nil
Copy link
Member

Choose a reason for hiding this comment

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

Something like this will be a bit clearer and swiftier

let expiresIn: Date?
switch json["expires_in"] {
case let string as String:
    guard let double = Double(string) else { break }
    expiresIn = Date(timeIntervalSince1970: double)
case let int as Int:
    expiresIn = Date(timeIntervalSince1970: Double(int))
case let double as Double:
    expiresIn = Date(timeIntervalSince1970: double)
default:
    expiresIn = nil
}

Copy link
Member Author

Choose a reason for hiding this comment

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

👍

@hzalaz hzalaz added this to the 1.1.0 milestone Dec 14, 2016
@hzalaz hzalaz merged commit 18d7e0b into master Dec 15, 2016
@hzalaz hzalaz deleted the add_credential_expires branch December 15, 2016 14:14
@hzalaz hzalaz changed the title expires_in supported in Credentials Credentials exposes expires_in if returned after auth Dec 15, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants