MCPcopy Create free account
hub / github.com/Rblp/Rblpapi / authenticateWithApp

Function authenticateWithApp

src/authenticate.cpp:114–181  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

112}
113
114Identity* authenticateWithApp(SEXP con_) {
115 Identity* identity_p = 0;
116
117 // via Rcpp Attributes we get a try/catch block with error propagation to R "for free"
118 Session* session =
119 reinterpret_cast<Session*>(checkExternalPointer(con_, "blpapi::Session*"));
120
121 // setup authorization service
122 std::string service("//blp/apiauth");
123
124 // authorize
125 if (session->openService(service.c_str())) {
126 Service authService = session->getService(service.c_str());
127 CorrelationId correlation_id(10);
128 std::string token;
129 EventQueue tokenEventQueue;
130 session->generateToken(correlation_id, &tokenEventQueue);
131 Event event = tokenEventQueue.nextEvent();
132 //
133 // get token for session
134 //
135 if(event.eventType() == Event::TOKEN_STATUS ||
136 event.eventType() == Event::REQUEST_STATUS) {
137 MessageIterator msgIter(event);
138 while(msgIter.next()) {
139 Message msg = msgIter.message();
140 if (msg.messageType() == "TokenGenerationSuccess") {
141 token = msg.getElementAsString("token");
142 } else if(msg.messageType() == "TokenGenerationFailure") {
143 Rcpp::stop("Failed to generate token");
144 }
145 }
146 }
147
148 //
149 // begin authorization
150 //
151 if(!token.empty()) {
152 Request authRequest = authService.createAuthorizationRequest();
153 authRequest.set("token", token.c_str());
154 identity_p = new Identity(session->createIdentity());
155 session->sendAuthorizationRequest(authRequest, identity_p);
156 // parse messages
157 bool message_found = false;
158 while(!message_found) {
159 Event event = session->nextEvent(100000);
160 if (event.eventType() == Event::RESPONSE ||
161 event.eventType() == Event::REQUEST_STATUS ||
162 event.eventType() == Event::PARTIAL_RESPONSE) {
163 MessageIterator msgIter(event);
164 while (msgIter.next()) {
165 Message msg = msgIter.message();
166 if (msg.messageType() == "AuthorizationSuccess") {
167 message_found = true;
168 } else {
169 Rcpp::stop(">>> Failed to Authorize");
170 }
171 }

Callers 1

authenticate_ImplFunction · 0.85

Calls 1

checkExternalPointerFunction · 0.85

Tested by

no test coverage detected