Skip to content

Commit

Permalink
Login.authorize
Browse files Browse the repository at this point in the history
  • Loading branch information
shadowfacts committed Aug 19, 2018
1 parent cf918af commit 6a03c64
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
7 changes: 5 additions & 2 deletions Sources/MastodonKit/Models/LoginSettings.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,10 @@ public class LoginSettings: Codable {
public let accessToken: String
/// Access token type.
public let accessTokenType: String
/// The refresh token.
public let refreshToken: String
/// Date when the access token was retrieved.
public let createdAt: TimeInterval
// public let createdAt: TimeInterval
/// Access scope.
private let scope: String
/// Access scopes.
Expand All @@ -27,7 +29,8 @@ public class LoginSettings: Codable {
private enum CodingKeys: String, CodingKey {
case accessToken = "access_token"
case accessTokenType = "token_type"
case refreshToken = "refresh_token"
case scope
case createdAt = "created_at"
// case createdAt = "created_at"
}
}
13 changes: 13 additions & 0 deletions Sources/MastodonKit/Requests/Login.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,17 @@ public struct Login {
let method = HTTPMethod.post(.parameters(parameters))
return Request<LoginSettings>(path: "/oauth/token", method: method)
}

public static func authorize(code: String, clientID: String, clientSecret: String) -> Request<LoginSettings> {
let parameters = [
Parameter(name: "client_id", value: clientID),
Parameter(name: "client_secret", value: clientSecret),
Parameter(name: "grant_type", value: "authorization_code"),
Parameter(name: "code", value: code)
]

let method = HTTPMethod.post(.parameters(parameters))
return Request<LoginSettings>(path: "/oauth/token", method: method)
}

}

0 comments on commit 6a03c64

Please sign in to comment.