예제 #1
0
        public IActionResult AquireToken([FromBody] AquireTokenRequest request)
        {
            var bot = _dbContext.Dashboards.Where(b => b.Id == request.DashboardId)
                      .Select(b => new
            {
                b.Id,
                b.Secret,
                AllowedScopes = b.Scopes.Select(bs => bs.ScopeName).ToList()
            })
                      .FirstOrDefault();


            if (bot == null)
            {
                throw new HttpStatusException(HttpStatusCode.BadRequest, "Dashboard with that id does not exist.");
            }

            if (!BCrypt.Net.BCrypt.Verify(request.Secret, bot.Secret))
            {
                throw new HttpStatusException(HttpStatusCode.Unauthorized, "Invalid secret provided.");
            }

            var claims = (request.RequestedScopes?.Intersect(bot.AllowedScopes, StringComparer.OrdinalIgnoreCase) ?? bot.AllowedScopes)
                         .Select(s => new Claim(s, string.Empty))
                         .Concat(new[] { new Claim(BOT_ID_CLAIM, request.DashboardId.ToString()) })
                         .ToList();

            var signingKey = Convert.FromBase64String(_configuration["JwtSigningKey"]);
            var newToken   = AuthenticationController.CreateJwtToken(claims, signingKey);

            return(Json(new AquireTokenResponse {
                Token = newToken
            }));
        }
예제 #2
0
파일: BotApi.cs 프로젝트: SOBotics/Higgs
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>Task of AquireTokenResponse</returns>
        public async System.Threading.Tasks.Task <AquireTokenResponse> BotAquireTokenPostAsync(AquireTokenRequest request = null)
        {
            ApiResponse <AquireTokenResponse> localVarResponse = await BotAquireTokenPostAsyncWithHttpInfo(request);

            return(localVarResponse.Data);
        }
예제 #3
0
파일: BotApi.cs 프로젝트: SOBotics/Higgs
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>Task of ApiResponse (AquireTokenResponse)</returns>
        public async System.Threading.Tasks.Task <ApiResponse <AquireTokenResponse> > BotAquireTokenPostAsyncWithHttpInfo(AquireTokenRequest request = null)
        {
            var    localVarPath         = "/Bot/AquireToken";
            var    localVarPathParams   = new Dictionary <String, String>();
            var    localVarQueryParams  = new List <KeyValuePair <String, String> >();
            var    localVarHeaderParams = new Dictionary <String, String>(Configuration.DefaultHeader);
            var    localVarFormParams   = new Dictionary <String, String>();
            var    localVarFileParams   = new Dictionary <String, FileParameter>();
            Object localVarPostBody     = null;

            // to determine the Content-Type header
            String[] localVarHttpContentTypes = new String[] {
                "application/json-patch+json",
                "application/json",
                "text/json",
                "application/_*+json"
            };
            String localVarHttpContentType = Configuration.ApiClient.SelectHeaderContentType(localVarHttpContentTypes);

            // to determine the Accept header
            String[] localVarHttpHeaderAccepts = new String[] {
                "text/plain",
                "application/json",
                "text/json"
            };
            String localVarHttpHeaderAccept = Configuration.ApiClient.SelectHeaderAccept(localVarHttpHeaderAccepts);

            if (localVarHttpHeaderAccept != null)
            {
                localVarHeaderParams.Add("Accept", localVarHttpHeaderAccept);
            }

            if (request != null && request.GetType() != typeof(byte[]))
            {
                localVarPostBody = Configuration.ApiClient.Serialize(request); // http body (model) parameter
            }
            else
            {
                localVarPostBody = request; // byte array
            }


            // make the HTTP request
            IRestResponse localVarResponse = (IRestResponse)await Configuration.ApiClient.CallApiAsync(localVarPath,
                                                                                                       Method.POST, localVarQueryParams, localVarPostBody, localVarHeaderParams, localVarFormParams, localVarFileParams,
                                                                                                       localVarPathParams, localVarHttpContentType);

            int localVarStatusCode = (int)localVarResponse.StatusCode;

            if (ExceptionFactory != null)
            {
                Exception exception = ExceptionFactory("BotAquireTokenPost", localVarResponse);
                if (exception != null)
                {
                    throw exception;
                }
            }

            return(new ApiResponse <AquireTokenResponse>(localVarStatusCode,
                                                         localVarResponse.Headers.ToDictionary(x => x.Name, x => x.Value.ToString()),
                                                         (AquireTokenResponse)Configuration.ApiClient.Deserialize(localVarResponse, typeof(AquireTokenResponse))));
        }
예제 #4
0
파일: BotApi.cs 프로젝트: SOBotics/Higgs
        /// <summary>
        ///
        /// </summary>
        /// <exception cref="IO.Swagger.Client.ApiException">Thrown when fails to make API call</exception>
        /// <param name="request"> (optional)</param>
        /// <returns>AquireTokenResponse</returns>
        public AquireTokenResponse BotAquireTokenPost(AquireTokenRequest request = null)
        {
            ApiResponse <AquireTokenResponse> localVarResponse = BotAquireTokenPostWithHttpInfo(request);

            return(localVarResponse.Data);
        }