Exemple #1
0
        public IAsyncOperation InitOAuth(string clientId, string clientSecret = null,
                                         string realm = null, string appName = null, string scopeSeparator = ":", bool usePKCE = false,
                                         Dictionary <string, string> aditionalQueryStringParams = null, bool scope_offline = false)
        {
            String[] scopes = null;
            if (scope_offline)
            {
                scopes = new string[] { "offline_access" };
            }
            else
            {
                scopes = new string[] { };
            }


            var tokenUrl = TokenPath ?? "https://sso.simva.e-ucm.es/auth/realms/simva/protocol/openid-connect/token";
            var authUrl  = AuthPath ?? "https://sso.simva.e-ucm.es/auth/realms/simva/protocol/openid-connect/auth";

            var done = new AsyncCompletionSource();

            OpenIdUtility.LoginWithAccessCode(authUrl, tokenUrl, clientId, null, string.Join(scopeSeparator, scopes), usePKCE)
            .Then(authInfo =>
            {
                AuthorizationInfo = authInfo;
                done.SetCompleted();
            })
            .Catch(error =>
            {
                done.SetException(new ApiException(500, error.Message));
            });

            return(done);
        }
Exemple #2
0
        public IAsyncOperation ContinueOAuth(string clientId)
        {
            var scopes = new string[] { };

            var tokenUrl = TokenPath ?? "https://sso.simva.e-ucm.es/auth/realms/simva/protocol/openid-connect/token";
            var authUrl  = AuthPath ?? "https://sso.simva.e-ucm.es/auth/realms/simva/protocol/openid-connect/auth";

            var done = new AsyncCompletionSource();

            try
            {
                OpenIdUtility.TryContinueLogin(tokenUrl, clientId)
                .Then(authInfo =>
                {
                    AuthorizationInfo = authInfo;
                    done.SetCompleted();
                });
            }
            catch (ApiException ex)
            {
                done.SetException(new ApiException(ex.ErrorCode, "Failed to renew AuthorizationInfo: " + ex.Message));
            }

            return(done);
        }