Last active
May 10, 2016 06:38
-
-
Save ashwinraghav/7795f07c5ad5f1482666 to your computer and use it in GitHub Desktop.
buzzfeed-digits auth snippets
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
func getDigitsAuthInfo(success:((info:NSDictionary)->()), failure:((error:NSError) ->())) { | |
let digitsAppearance = DGTAppearance() | |
// Change color properties to customize the look: | |
digitsAppearance.backgroundColor = kCuteYellowColor | |
digitsAppearance.accentColor = kCuteRedColor | |
let digits = Digits.sharedInstance() | |
digits.authenticateWithDigitsAppearance(digitsAppearance, viewController: nil, title: nil, completion: { (session, err) in | |
if (err == nil) { | |
let sessionDict = NSMutableDictionary(capacity: 8) | |
let oauthSigning = TWTROAuthSigning(authConfig: Twitter.sharedInstance().authConfig, authSession: session) | |
let authHeaders = oauthSigning.OAuthEchoHeadersToVerifyCredentials() | |
let requestURLString: AnyObject? = authHeaders[TWTROAuthEchoRequestURLStringKey] | |
let authorizationHeader: AnyObject? = authHeaders[TWTROAuthEchoAuthorizationHeaderKey] | |
sessionDict["requestURLString"] = requestURLString | |
sessionDict["userID"] = session.userID | |
sessionDict["phoneNumber"] = session.phoneNumber | |
success(info: sessionDict); | |
} else { | |
failure(error:err) | |
} | |
}) | |
} | |
func logout() { | |
Digits.sharedInstance().logOut() | |
} | |
} |
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
import urllib2 | |
def authenticate_digits(self, request): | |
authHeader = self.request.QUERY_PARAMS.get('authHeader', None) | |
requestURLString = self.request.QUERY_PARAMS.get('requestURLString', None) | |
req = urllib2.Request(requestURLString) | |
req.add_header('Authorization', authHeader) | |
resp = urllib2.urlopen(req) | |
content = resp.read() | |
print content #should print something like {"id":2131231231,"id_str":"2131231231","created_at":"Fri Jan 16 19:38:13 +0000 2015"} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment