/// <summary>
        /// Initializes an new instance of the LiveAuthClientCore class.
        /// </summary>
        public LiveAuthClientCore(
            string clientId,
            IDictionary<int, string> clientSecretMap, 
            IRefreshTokenHandler refreshTokenHandler,
            LiveAuthClient authClient)
        {
            Debug.Assert(!string.IsNullOrEmpty(clientId));
            Debug.Assert(clientSecretMap != null && clientSecretMap.Count > 0);
            Debug.Assert(authClient != null);

            this.clientId = clientId;
            this.clientSecrets = clientSecretMap;
            this.refreshTokenHandler = refreshTokenHandler;
            this.publicAuthClient = authClient;

            // Get latest version
            int largestIndex = clientSecretMap.Keys.First();
            if (clientSecretMap.Count > 1)
            {
                foreach (int index in clientSecretMap.Keys)
                {
                    if (index > largestIndex)
                    {
                        largestIndex = index;
                    }
                }
            }

            this.clientSecret = clientSecretMap[largestIndex];
        }
Example #2
0
        /// <summary>
        /// Initializes an new instance of the LiveAuthClientCore class.
        /// </summary>
        public LiveAuthClientCore(
            string clientId,
            IDictionary <int, string> clientSecretMap,
            IRefreshTokenHandler refreshTokenHandler,
            LiveAuthClient authClient)
        {
            Debug.Assert(!string.IsNullOrEmpty(clientId));
            Debug.Assert(clientSecretMap != null && clientSecretMap.Count > 0);
            Debug.Assert(authClient != null);

            this.clientId            = clientId;
            this.clientSecrets       = clientSecretMap;
            this.refreshTokenHandler = refreshTokenHandler;
            this.publicAuthClient    = authClient;

            // Get latest version
            int largestIndex = clientSecretMap.Keys.First();

            if (clientSecretMap.Count > 1)
            {
                foreach (int index in clientSecretMap.Keys)
                {
                    if (index > largestIndex)
                    {
                        largestIndex = index;
                    }
                }
            }

            this.clientSecret = clientSecretMap[largestIndex];
        }
Example #3
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");

            this.authClient  = new LiveAuthClientCore(clientId, refreshTokenHandler, this);
            this.syncContext = SynchronizationContextWrapper.Current;
        }
Example #4
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");

            this.authClient = new LiveAuthClientCore(clientId, refreshTokenHandler, this);
            this.syncContext = SynchronizationContextWrapper.Current;
        }
Example #5
0
 public TokenService(
     IJwtHandler jwtHandler,
     IRefreshTokenHandler refreshHandler,
     ITokenRepository tokenRepository
     )
 {
     _jwtHandler      = jwtHandler;
     _refreshHandler  = refreshHandler;
     _tokenRepository = tokenRepository;
 }
 public AuthController(ILogger <UserController.UserController> logger, IJwtService jwtService,
                       UserManager <User> userManager, ILoginHandler loginHandler, IRefreshTokenHandler refreshTokenHandler,
                       ILogoutHandler logoutHandler)
 {
     _logger              = logger;
     _jwtService          = jwtService;
     _userManager         = userManager;
     _loginHandler        = loginHandler;
     _refreshTokenHandler = refreshTokenHandler;
     _logoutHandler       = logoutHandler;
 }
        /// <summary>
        /// Initializes a new instance of the LiveAuthClientCore class.
        /// </summary>
        public LiveAuthClientCore(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler,
            LiveAuthClient authClient)
        {
            Debug.Assert(!string.IsNullOrEmpty(clientId));
            Debug.Assert(authClient != null);

            this.clientId            = clientId;
            this.refreshTokenHandler = refreshTokenHandler;
            this.publicAuthClient    = authClient;
        }
        /// <summary>
        /// Initializes a new instance of the LiveAuthClientCore class.
        /// </summary>
        public LiveAuthClientCore(
            string clientId,
            IRefreshTokenHandler refreshTokenHandler,
            LiveAuthClient authClient)
        {
            Debug.Assert(!string.IsNullOrEmpty(clientId));
            Debug.Assert(authClient != null);

            this.clientId = clientId;
            this.refreshTokenHandler = refreshTokenHandler;
            this.publicAuthClient = authClient;
        }
Example #9
0
        public AuthController(
            IRefreshTokenHandler _refreshTokenHandler,
            IAccessTokenHandler _accessTokenHandler,
            IDatabaseAccess _database, IHasher _hasher,
            IConfiguration configuration)
        {
            refreshTokenHandler = _refreshTokenHandler;
            accessTokenHandler  = _accessTokenHandler;
            database            = _database;
            hasher = _hasher;

            bypassSecureCookies = configuration.GetValue("WebServer:Auth:BypassSecureCookies", false);
        }
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="clientSecret">The client secret of the app.</param>
        /// <param name="defaultRedirectUrl">The default redirect URL for the site.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            string clientSecret,
            string defaultRedirectUrl,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientSecret, "clientSecret");
            if (!string.IsNullOrWhiteSpace(defaultRedirectUrl))
            {
                LiveUtility.ValidateUrl(defaultRedirectUrl, "defaultRedirectUrl");
                this.defaultRedirectUrl = defaultRedirectUrl;
            }

            this.authClient = new LiveAuthClientCore(clientId, clientSecret, refreshTokenHandler, this);
        }
Example #11
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="clientSecret">The client secret of the app.</param>
        /// <param name="defaultRedirectUrl">The default redirect URL for the site.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            string clientSecret,
            string defaultRedirectUrl,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientSecret, "clientSecret");
            if (!string.IsNullOrWhiteSpace(defaultRedirectUrl))
            {
                LiveUtility.ValidateUrl(defaultRedirectUrl, "defaultRedirectUrl");
                this.defaultRedirectUrl = defaultRedirectUrl;
            }

            this.authClient = new LiveAuthClientCore(clientId, clientSecret, refreshTokenHandler, this);
        }
        public LiveService(IRefreshTokenHandler refreshTokenHandler, ILiveAuthClient authClient, IConfigurationService configurationService)
        {
            _refreshTokenHandler = refreshTokenHandler;
            _configurationService = configurationService;
            _authClient = authClient;

            _refreshTimer = new Timer();
            ConfigureRefreshTimer();

            _configurationService.PropertyChanged += (_, args) =>
            {
                if (args.PropertyName == "TokenExpiration")
                {
                    ConfigureRefreshTimer();
                }
            };
        }
        public LiveService(IRefreshTokenHandler refreshTokenHandler, ILiveAuthClient authClient, IConfigurationService configurationService)
        {
            _refreshTokenHandler  = refreshTokenHandler;
            _configurationService = configurationService;
            _authClient           = authClient;

            _refreshTimer = new Timer();
            ConfigureRefreshTimer();

            _configurationService.PropertyChanged += (_, args) =>
            {
                if (args.PropertyName == "TokenExpiration")
                {
                    ConfigureRefreshTimer();
                }
            };
        }
Example #14
0
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// To address security concerns, developers may wish to change their client secret. This constructor allows
        /// the developer to pass in a client secret map to handle the client secret change and ensure a graceful experience
        /// during the change rollover. You can create a new secret for your app on the developer portal (https://account.live.com/developers/applications)
        /// site. Once a new secret is created, the site will indicate the version of each secret, new and old.
        /// For example, the old secret and new secret may be shown as v0 and v1 on the developer portal site.
        /// Before the new secret is activated, both secrets are accepted by the Microsoft authentication server. You should update your
        /// code to provide the secret map when intializing a LiveAuthClient instance. This will ensure that the new secret
        /// will be used when communicating with the Microsoft authentication server, and the LiveAuthClient instance will use the correct version of
        /// the client secret to validate authentication tokens that may be signed by either old or new versions of client secret.
        /// Once you activate the new secret on the developer portal site, the old secret will no longer be accepted by the Microsoft
        /// authentication server, however, you may still want to keep the old secret in the map for one day, so that
        /// clients with authentication tokens signed with the old secret will continue to work.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="clientSecretMap">The client secret map of the app.</param>
        /// <param name="defaultRedirectUrl">The default redirect URL for the site.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IDictionary <int, string> clientSecretMap,
            string defaultRedirectUrl,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");
            LiveUtility.ValidateNotNullParameter(clientSecretMap, "clientSecretMap");
            if (clientSecretMap.Count == 0)
            {
                throw new ArgumentException("Client secret must be provided.", "clientSecretMap");
            }

            if (!string.IsNullOrWhiteSpace(defaultRedirectUrl))
            {
                LiveUtility.ValidateUrl(defaultRedirectUrl, "defaultRedirectUrl");
                this.defaultRedirectUrl = defaultRedirectUrl;
            }

            this.authClient = new LiveAuthClientCore(clientId, clientSecretMap, refreshTokenHandler, this);
        }
        public static async Task<Microsoft.OneDrive.OneDriveClient> GetOneDriveClientAsync(string clientId, OneDriveScopes[] scopes, IRefreshTokenHandler refreshTokenHandler = null)
        {
            LiveAuthClient authClient = new LiveAuthClient(clientId, refreshTokenHandler);
            var authScopes = from s in scopes select OAuthScopeAttribute.OAuthScopeForEnumValue(s);

            LiveLoginResult loginResult = await authClient.IntializeAsync(authScopes);
            if (loginResult.Status == LiveConnectSessionStatus.Connected)
            {
                return new OneDriveClient(new LiveConnectClient(loginResult.Session));
            }

            string startUrl = authClient.GetLoginUrl(authScopes);
            string endUrl = OAuthDesktopEndPoint;
            FormMicrosoftAccountAuth authForm = new FormMicrosoftAccountAuth(startUrl, endUrl);

            DialogResult result = await authForm.ShowDialogAsync();
            if (DialogResult.OK == result)
            {
                return await OnAuthComplete(authClient, authForm.AuthResult);
            }

            return null;
        }
        public static async Task <Microsoft.OneDrive.OneDriveClient> GetOneDriveClientAsync(string clientId, OneDriveScopes[] scopes, IRefreshTokenHandler refreshTokenHandler = null)
        {
            LiveAuthClient authClient = new LiveAuthClient(clientId, refreshTokenHandler);
            var            authScopes = from s in scopes select OAuthScopeAttribute.OAuthScopeForEnumValue(s);

            LiveLoginResult loginResult = await authClient.IntializeAsync(authScopes);

            if (loginResult.Status == LiveConnectSessionStatus.Connected)
            {
                return(new OneDriveClient(new LiveConnectClient(loginResult.Session)));
            }

            string startUrl = authClient.GetLoginUrl(authScopes);
            string endUrl   = OAuthDesktopEndPoint;
            FormMicrosoftAccountAuth authForm = new FormMicrosoftAccountAuth(startUrl, endUrl);

            DialogResult result = await authForm.ShowDialogAsync();

            if (DialogResult.OK == result)
            {
                return(await OnAuthComplete(authClient, authForm.AuthResult));
            }

            return(null);
        }
        /// <summary>
        /// Initializes an instance of LiveAuthClient class.
        /// To address security concerns, developers may wish to change their client secret. This constructor allows
        /// the developer to pass in a client secret map to handle the client secret change and ensure a graceful experience
        /// during the change rollover. You can create a new secret for your app on the developer portal (https://account.live.com/developers/applications)
        /// site. Once a new secret is created, the site will indicate the version of each secret, new and old.
        /// For example, the old secret and new secret may be shown as v0 and v1 on the developer portal site.
        /// Before the new secret is activated, both secrets are accepted by the Microsoft authentication server. You should update your 
        /// code to provide the secret map when intializing a LiveAuthClient instance. This will ensure that the new secret
        /// will be used when communicating with the Microsoft authentication server, and the LiveAuthClient instance will use the correct version of
        /// the client secret to validate authentication tokens that may be signed by either old or new versions of client secret. 
        /// Once you activate the new secret on the developer portal site, the old secret will no longer be accepted by the Microsoft 
        /// authentication server, however, you may still want to keep the old secret in the map for one day, so that 
        /// clients with authentication tokens signed with the old secret will continue to work.
        /// </summary>
        /// <param name="clientId">The client Id of the app.</param>
        /// <param name="clientSecretMap">The client secret map of the app.</param>
        /// <param name="defaultRedirectUrl">The default redirect URL for the site.</param>
        /// <param name="refreshTokenHandler">An IRefreshTokenHandler instance to handle refresh token persistency and retrieval.</param>
        public LiveAuthClient(
            string clientId,
            IDictionary<int, string> clientSecretMap,
            string defaultRedirectUrl,
            IRefreshTokenHandler refreshTokenHandler)
        {
            LiveUtility.ValidateNotNullOrWhiteSpaceString(clientId, "clientId");
            LiveUtility.ValidateNotNullParameter(clientSecretMap, "clientSecretMap");
            if (clientSecretMap.Count == 0)
            {
                throw new ArgumentException("Client secret must be provided.", "clientSecretMap");
            }

            if (!string.IsNullOrWhiteSpace(defaultRedirectUrl))
            {
                LiveUtility.ValidateUrl(defaultRedirectUrl, "defaultRedirectUrl");
                this.defaultRedirectUrl = defaultRedirectUrl;
            }

            this.authClient = new LiveAuthClientCore(clientId, clientSecretMap, refreshTokenHandler, this);   
        }
Example #18
0
 public Authenticator(string clientId, IRefreshTokenHandler tokenHandler)
 {
     _clientId = clientId;
     _tokenHandler = tokenHandler;
 }