예제 #1
0
 internal MASUser(Configuration config, MASDevice device)
 {
     _config        = config;
     _device        = device;
     _storage       = new SecureStorage();
     _sharedStorage = new SharedSecureStorage();
 }
예제 #2
0
        internal static async Task <MASUser> InitializeAsync(Configuration config, MASDevice device, bool isAnonymous)
        {
            var user = new MASUser(config, device);

            user._isAnonymous = isAnonymous;

            await user.LoadAsync();

            if (!isAnonymous && user.IsLoggedIn)
            {
                MASUser.Current = user;
            }

            return(user);
        }
예제 #3
0
        internal async Task ResetAsync()
        {
            Logger.LogInfo("Framework reseting...");

            MASDevice.Reset();

            MASUser.Reset();

            await SecureStorage.ResetAsync();

            await SharedSecureStorage.ResetAsync();

            await CertManager.UninstallAsync();

            HttpRequestFactory.CancelAll();

            Logger.LogInfo("Framework reset");
        }
예제 #4
0
 internal static async Task InitializeAsync(Configuration config)
 {
     Current = new MASDevice(config);
     await Current.LoadAsync();
 }
예제 #5
0
        internal async Task StartAsync(string configContent, RegistrationKind regKind)
        {
            Logger.LogInfo("Framework starting...");

            // Load and validate configuration data
            var config = new Configuration();

            config.Load(configContent);
            _config = config;

            var clientId = config.DefaultClientId;

            Organization        = config.OAuth.Client.Organization;
            Name                = config.OAuth.Client.ClientName;
            DetailedDescription = config.OAuth.Client.Description;

            Identifier    = config.DefaultClientId.Id;
            Environment   = config.DefaultClientId.Environment;
            RegisteredBy  = config.DefaultClientId.RegisteredBy;
            Scope         = new List <string>(config.DefaultClientId.Scope.Split(' ').Where(s => !string.IsNullOrWhiteSpace(s))).AsReadOnly();
            ScopeAsString = config.DefaultClientId.Scope;
            Status        = config.DefaultClientId.Status;

            RedirectUri = config.DefaultClientId.RedirectUri;

            // Load device and any previous registration info.
            await MASDevice.InitializeAsync(config);

            // Authorization providers not supported yet
            //var response = await MAGRequests.GetAuthorizationProviders(_config, Device);

            // Load client access if client registration is requested
            if (MAS.RegistrationKind == RegistrationKind.Client)
            {
                Client = await MASUser.InitializeAsync(config, MASDevice.Current, true);
            }

            // Load user and any previous access token or idtoken info
            await MASUser.InitializeAsync(config, MASDevice.Current, false);

            if (!MASDevice.Current.IsRegistered)
            {
                switch (regKind)
                {
                case RegistrationKind.Client:
                    if (!config.HasScope(ScopeNames.MssoClientRegister))
                    {
                        ErrorFactory.ThrowError(ErrorCode.DeviceRegistrationAttemptedWithUnregisteredScope);
                    }

                    await MASDevice.Current.RegisterWithClientAsync();

                    // Create a device anonymous user
                    var clientUser = new MASUser(_config, MASDevice.Current);
                    await clientUser.LoginAnonymouslyAsync();

                    Client = clientUser;

                    break;

                case RegistrationKind.User:
                    // Ask for login with user device registration
                    LoginRequested?.Invoke(null, EventArgs.Empty);
                    break;

                default:
                    ErrorFactory.ThrowError(ErrorCode.DeviceRegistrationAttemptedWithUnregisteredScope);
                    break;
                }
            }

            Logger.LogInfo("Framework started");
        }