Experience LoginExperience {
Decision ruleSingInEventbrite action("LoginContext.ruleSingInEventbrite") label("Signin with Eventbrite")
}
RuleContext LoginContext {
Rule ruleSingInEventbrite {
OAuth oauth = OAuth()
oauth.clientID = "...COMPLETE..."
oauth.secret = "...COMPLETE..."
oauth.redirectURL = "...COMPLETE..."
oauth.accountName = oauth.clientID + oauth.secret
oauth.authorizationURL = "https://www.eventbrite.com/oauth/authorize?response_type=token&client_id=" + oauth.clientID
oauth.tokenURL = "https://www.eventbrite.com/oauth/token"
token = broker.oauth.authenticate(oauth)
if (token != null) { //successfully authentication
EventBriteLib::EBProfileResponse profileRsp = service.EventBriteLib::eb_getProfile.call(token)
loggedUser = User(name:profileRsp.name, eventbriteId:profileRsp.eventbriteId)
//persist logged user info
broker.localPersistence.save(loggedUserNameKey, loggedUser.name)
broker.localPersistence.save(loggedUserEventbriteIDKey, loggedUser.eventbriteId)
//persist token in keychain
broker.localKeychain.save(ebUserTokenKey, token)
//show Events experience
broker.ui.push("EventsExperience")
}
}
}