コード例 #1
0
        public static async Task <TokenResponse> RequestTokenAsync(ResourceOwnerAuthorizationOptions authorizationOptions, HttpClient httpClient)
        {
            var disco = await httpClient.GetDiscoveryDocumentAsync(
                new DiscoveryDocumentRequest
            {
                Address = authorizationOptions.Authority,
                Policy  =
                {
                    ValidateIssuerName = authorizationOptions.ValidateDiscoveryDocument,
                    ValidateEndpoints  = authorizationOptions.ValidateDiscoveryDocument,
                },
            }
                );

            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }

            PasswordTokenRequest request = new PasswordTokenRequest
            {
                Address      = disco.TokenEndpoint,
                ClientId     = authorizationOptions.ClientId,
                ClientSecret = string.IsNullOrEmpty(authorizationOptions.ClientSecret) ? null : authorizationOptions.ClientSecret,
                Password     = authorizationOptions.Password,
                Scope        = authorizationOptions.Scope,
                UserName     = authorizationOptions.UserName
            };

            return(await httpClient.RequestPasswordTokenAsync(request));
        }
コード例 #2
0
 public EventService(
     AlloyContext context,
     IAuthorizationService authorizationService,
     IPrincipal user,
     IMapper mapper,
     IPlayerService playerService,
     ISteamfitterService steamfitterService,
     ICasterService casterService,
     IAlloyEventQueue alloyBackgroundService,
     ILogger <EventService> logger,
     IOptionsMonitor <ResourceOptions> resourceOptions,
     IUserClaimsService claimsService,
     ResourceOwnerAuthorizationOptions resourceOwnerAuthorizationOptions,
     ClientOptions clientOptions,
     IHttpClientFactory httpClientFactory,
     IServiceProvider serviceProvider)
 {
     _context = context;
     _authorizationService = authorizationService;
     _user               = user as ClaimsPrincipal;
     _mapper             = mapper;
     _casterService      = casterService;
     _playerService      = playerService;
     _steamfitterService = steamfitterService;
     _alloyEventQueue    = alloyBackgroundService;
     _logger             = logger;
     _resourceOptions    = resourceOptions;
     _claimsService      = claimsService;
     _resourceOwnerAuthorizationOptions = resourceOwnerAuthorizationOptions;
     _clientOptions     = clientOptions;
     _httpClientFactory = httpClientFactory;
     _serviceProvider   = serviceProvider;
 }
コード例 #3
0
        public static async Task <TokenResponse> RequestTokenAsync(ResourceOwnerAuthorizationOptions authorizationOptions)
        {
            var disco = await DiscoveryClient.GetAsync(authorizationOptions.Authority);

            if (disco.IsError)
            {
                throw new Exception(disco.Error);
            }

            TokenClient client = null;

            if (string.IsNullOrEmpty(authorizationOptions.ClientSecret))
            {
                client = new TokenClient(disco.TokenEndpoint, authorizationOptions.ClientId);
            }
            else
            {
                client = new TokenClient(disco.TokenEndpoint, authorizationOptions.ClientId, authorizationOptions.ClientSecret);
            }

            return(await client.RequestResourceOwnerPasswordAsync(authorizationOptions.UserName, authorizationOptions.Password, authorizationOptions.Scope));
        }