Skip to content

Instantly share code, notes, and snippets.

@d4r1091
Last active October 12, 2019 07:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save d4r1091/c96fb4a2b7f90596646c56abd2888f97 to your computer and use it in GitHub Desktop.
Save d4r1091/c96fb4a2b7f90596646c56abd2888f97 to your computer and use it in GitHub Desktop.
Encode Token protocol Swift
//
// 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