コード例 #1
0
 public JwtAuthService(ITokenProvider tokenProvider, AuthenticationStateProvider authenticationStateProvider, ITokenStorageService tokenStorageService, IOptions <AuthOptions> options)
 {
     _tokenProvider        = tokenProvider;
     _tokenStorageService  = tokenStorageService;
     _jwtAuthStateProvider = authenticationStateProvider as JwtAuthStateProvider;
     _options = options;
 }
コード例 #2
0
 public JwtAuthStateProvider(ITokenProvider tokenProvider, ILocalStorageService localStorageService, ITokenStorageService tokenStorageService, IOptions <AuthOptions> options, ILogger <JwtAuthStateProvider> logger)
 {
     _tokenProvider       = tokenProvider;
     _localStorageService = localStorageService;
     _tokenStorageService = tokenStorageService;
     _options             = options;
     _logger = logger;
 }
コード例 #3
0
ファイル: AccountService.cs プロジェクト: mumby0168/VMS
        public AccountService(HttpClient client, ITokenStorageService tokenStorage, ILogger <AccountService> logger, Endpoints endpoints)
        {
            _tokenStorage      = tokenStorage;
            _logger            = logger;
            client.BaseAddress = new System.Uri(endpoints.Identity);
            if (_tokenStorage.Token != null)
            {
                _isAuthHeaderSet = true;
                client.DefaultRequestHeaders.Add("Authorization", $"Bearer {_tokenStorage.Token.RawToken}");
            }

            Client = client;
        }
コード例 #4
0
 public void Setup()
 {
     clientConsumer = A.Fake<IClientConsumer>();
     tokenService = A.Fake<ITokenStorageService>();
     httpRequestReader = A.Fake<IHttpRequestReader>();
     client = new OAuthClient(clientConsumer, tokenService, httpRequestReader);
 }
コード例 #5
0
 public HttpService(HttpClient httpClient, ITokenStorageService tokenStorageService)
 {
     _httpClient          = httpClient;
     _tokenStorageService = tokenStorageService;
 }
コード例 #6
0
 public IdentityHttpService(HttpClient httpClient, ITokenStorageService tokenStorageService)
     : base(httpClient, tokenStorageService)
 {
 }
コード例 #7
0
        public void Configure(IApplicationBuilder app, IServiceProvider serviceProvider, ITokenStorageService tsp, IHttpContextAccessor httpContextAccessor)
        {
            app.UseStaticFiles();

            app.UseSession();

            app.UseCookieAuthentication(new CookieAuthenticationOptions
            {
                AutomaticAuthenticate = true,
                AutomaticChallenge    = true,
                CookieName            = "LocalAuthCookie",
                LoginPath             = new PathString("/signin"),
                AccessDeniedPath      = new PathString("/?err=Access%20denied"),
                LogoutPath            = new PathString("/signout")
            });


            //var httpContextAccessor = serviceProvider.GetService<IHttpContextAccessor>();
            //SLO link https://sso.demo.notakey.com/sso/saml2/idp/initSLO?RelayState=http://localhost:5000/
            app.UseOAuthAuthentication(new OAuthOptions
            {
                DisplayName             = "NotakeySSO",
                SaveTokens              = true,
                AuthenticationScheme    = "Application",
                AuthorizationEndpoint   = "https://sso.demo.notakey.com/sso/module/oauth2/authorize",
                TokenEndpoint           = "https://sso.demo.notakey.com/sso/module/oauth2/access_token",
                UserInformationEndpoint = "https://sso.demo.notakey.com/sso/module/oauth2/userinfo",
                ClientId     = "_62e84e38c015008ae22ca1d11a616c48d72e4b7a9c",
                ClientSecret = "_177efa03b58eaa75001a595930217fd8a12e049509",
                Scope        = { "basic" },
                CallbackPath = new PathString("/callback"),
                Events       = new OAuthEvents
                {
                    OnCreatingTicket = async context => { await CreateAuthTicket(context, tsp, httpContextAccessor); },

                    OnRemoteFailure = context => {
                        context.Response.Redirect("/?err=" + UrlEncoder.Default.Encode(context.Failure.Message));
                        context.HandleResponse();
                        return(Task.FromResult(0));
                    }
                }
            });

            app.UseMvc();
        }
コード例 #8
0
        private async Task CreateAuthTicket(OAuthCreatingTicketContext context, ITokenStorageService tsp, IHttpContextAccessor htc)
        {
            // Get the User info using the bearer token
            var request = new HttpRequestMessage()
            {
                RequestUri = new Uri(context.Options.UserInformationEndpoint),
                Method     = HttpMethod.Get
            };

            request.Headers.Authorization = new AuthenticationHeaderValue("Bearer", context.AccessToken);
            request.Headers.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));

            var response = await context.Backchannel.SendAsync(request, context.HttpContext.RequestAborted);

            response.EnsureSuccessStatusCode();

            var     converter = new ExpandoObjectConverter();
            dynamic user      = JsonConvert.DeserializeObject <ExpandoObject>(await response.Content.ReadAsStringAsync(), converter);

            Console.WriteLine("Added username: "******": " + attr[0]);

                    if (u.Key == "mail")
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.Email, (string)attr[0]));
                    }
                    if (u.Key == "lastName")
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.Surname, (string)attr[0]));
                    }
                    if (u.Key == "firstName")
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.GivenName, (string)attr[0]));
                    }
                    if (u.Key == "mainPhone")
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.MobilePhone, (string)attr[0]));
                    }
                    if (u.Key == "guid")
                    {
                        context.Identity.AddClaim(new Claim(ClaimTypes.Sid, (string)attr[0]));
                    }
                    if (u.Key == "authId")
                    {
                        context.Identity.AddClaim(new Claim("auth-id", (string)attr[0]));
                    }
                }
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
            }

            tsp.saveRefreshToken(context.RefreshToken);
            tsp.saveAccessToken(context.AccessToken);
            tsp.saveExpirationTime((TimeSpan)context.ExpiresIn);


            //var dateFirstSeen = DateTime.Now;
            //var serialisedDate = JsonConvert.SerializeObject(dateFirstSeen);
            ////AppContext.Session.SetString("RefreshToken", context.RefreshToken);

            ////RefreshToken = context.RefreshToken;
            ////TokenType = context.TokenType;
            //ExpiresIn = (TimeSpan)context.ExpiresIn;
            //AccessToken = context.AccessToken;
        }
コード例 #9
0
 public SystemAdminAuthenticationStateProvider(ITokenStorageService tokenStorageService, ILogger <SystemAdminAuthenticationStateProvider> logger)
 {
     this._tokenStorageService = tokenStorageService;
     this._logger = logger;
 }
コード例 #10
0
ファイル: OAuthClient.cs プロジェクト: drewzif84/OAuthClient
 public OAuthClient(IClientConsumer consumer, ITokenStorageService tokenService, IHttpRequestReader httpRequestReader)
 {
     this.consumer = consumer;
     this.tokenService = tokenService;
     this.httpRequestReader = httpRequestReader;
 }