Last active
October 12, 2019 07:52
-
-
Save d4r1091/c96fb4a2b7f90596646c56abd2888f97 to your computer and use it in GitHub Desktop.
Encode Token protocol Swift
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
// | |
// Tokenable.swift | |
// | |
// Created by Dario Carlomagno on 27/07/2019. | |
// | |
import Foundation | |
protocol Tokenable { | |
static var encodedToken: String { get } | |
} | |
extension Tokenable { | |
static var encodedToken: String { | |
guard let data = NSMutableData(length: AccessToken.length) else { | |
return "" | |
} | |
let _ = SecRandomCopyBytes(kSecRandomDefault, data.length, data.mutableBytes) | |
return data.base64EncodedString(options: []) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment