We had earlier asked a question regarding migrating the data from Authy to Verify API. We were following the steps provided in this URL.
(https://www.stackoverflow.com/questions/74302235/migrate-authy-totp-to-verify)
However, when we are migrating the user, the user is not verified even after the migration. Here is the code which we are using
Dim oAuthy = New clsAuthy(apiKey, False)
'Fetch details from authy to migrate to verify
Dim authyDetails As clsAuthySecret = oAuthy.GetAuthyDetails(item("TwilioAuthyId"))
oAuthy = Nothing
'Migrate data to verify API
With oVerify
.GenerateQRCode(item("UserName"), item("UserId").ToString(), authyDetails.Secret)
.VerifyToken(.FactorID, authyDetails.OTP, item("UserId").ToString())
FactorId = .FactorID
VerifyUrl = .QrUrl
End With
Public Function GetAuthyDetails(ByRef AuthyID As String) As clsAuthySecret
Dim apiResponse As clsAuthySecret
Dim url = String.Format("{0}/protected/json/users/{1}/secret/export", Me.baseUrl, AuthyID, Me.apikey)
Try
client.Headers.Set("X-Authy-API-Key", Me.apikey)
Dim response = client.DownloadString(url)
apiResponse = JsonConvert.DeserializeObject(Of clsAuthySecret)(response)
apiResponse.RawResponse = response
Catch ex As WebException
apiResponse = New clsAuthySecret()
apiResponse.Status = AuthyStatus.BadRequest 'bad request
apiResponse.Message = ex.Message
'apiResponse.RawResponse = ex.Response.ToString()
End Try
If (apiResponse.Success) Then
apiResponse.Status = AuthyStatus.Success
End If
Return apiResponse
End Function
Public Function GenerateQRCode(ByVal Email As String,
ByVal UserID As String,
ByVal Secret As String
) As Task(Of Boolean)
Try
TwilioClient.Init(_accountSID, _authToken)
Dim newFactor = NewFactorResource.Create(friendlyName:=Email,
factorType:=NewFactorResource.FactorTypesEnum.Totp,
pathServiceSid:=_serviceSID,
pathIdentity:=UserID.ToLower(),
bindingSecret:=Secret)
_factorID = newFactor.Sid
_qrUrl = JObject.Parse(newFactor.Binding.ToString())("uri")
Catch ex As Exception
_responseMessage = ex.Message
Return False
End Try
Return True
End Function
Public Function VerifyToken(ByVal FactorID As String,
ByVal Token As String,
ByVal UserID As String
) As Task(Of Boolean)
Try
TwilioClient.Init(_accountSID, _authToken)
Dim factor = FactorResource.Update(authPayload:=Token,
pathServiceSid:=_serviceSID,
pathIdentity:=UserID.ToLower(),
pathSid:=FactorID)
If factor.Status.ToString = "verified" Then
Return True
Else
Return False
End If
Catch ex As Exception
_responseMessage = ex.Message
Return False
End Try
End Function
Is there anything we are missing from our end? Following is the response as shown in the image link below
https://i.stack.imgur.com/lhTkE.png
Related
I am trying to unlock the machine by passing user id and password in UiPath when scheduled bot trying to run the process in locked system
Below is my code
'Create a new pipe client
Using pipeClient As New System.IO.Pipes.NamedPipeClientStream(
".",
"CredentialProviderPipe",
PipeDirection.InOut,
PipeOptions.None,
System.Security.Principal.TokenImpersonationLevel.Impersonation)
'Attempt to connect to it
pipeClient.Connect(10000)
'Send credentials
Dim dom As String
If Domain = "" Then
dom = Environment.UserDomainName
Else
dom = Domain
End If
Dim ss As New StreamString(pipeClient)
ss.WriteString(String.Format("LOGON{0}{1}{0}{2}{0}{3}", vbLf, dom, Username, Password))
'Wait for reply
Using pr As New StreamReader(pipeClient, System.Text.Encoding.Unicode)
Response = pr.ReadLine()
If Response = "OK" OrElse Response = "UNKNOWN" Then Return
ErrorCode = pr.ReadLine()
ErrorMessage = pr.ReadLine()
End Using
End Using
Catch ex As TimeoutException
Response = "ERROR"
ErrorCode = "0x80131505"
ErrorMessage = ex.Message
Catch ex As Exception
Response = "ERROR"
ErrorCode = ""
ErrorMessage = ex.Message
End Try
I am getting below error that error BC30002: Type StringStream is not defined.
I dont know how to resolve the issue. Please help
It looks like all those uses of StreamString are based on the example here, which includes the definition of that class as below:
' Defines the data protocol for reading and writing strings on our stream
Public Class StreamString
Private ioStream As Stream
Private streamEncoding As UnicodeEncoding
Public Sub New(ioStream As Stream)
Me.ioStream = ioStream
streamEncoding = New UnicodeEncoding(False, False)
End Sub
Public Function ReadString() As String
Dim len As Integer = 0
len = CType(ioStream.ReadByte(), Integer) * 256
len += CType(ioStream.ReadByte(), Integer)
Dim inBuffer As Array = Array.CreateInstance(GetType(Byte), len)
ioStream.Read(inBuffer, 0, len)
Return streamEncoding.GetString(inBuffer)
End Function
Public Function WriteString(outString As String) As Integer
Dim outBuffer() As Byte = streamEncoding.GetBytes(outString)
Dim len As Integer = outBuffer.Length
If len > UInt16.MaxValue Then
len = CType(UInt16.MaxValue, Integer)
End If
ioStream.WriteByte(CType(len \ 256, Byte))
ioStream.WriteByte(CType(len And 255, Byte))
ioStream.Write(outBuffer, 0, outBuffer.Length)
ioStream.Flush()
Return outBuffer.Length + 2
End Function
End Class
I am trying to run a httplistener in order to receive a call back from an web application
However the never goes past context = Await httpListener.GetContextAsync
I can telnet to the port of the listener and it responds.
Class SSO
Public Sub AuthorizeAsync()
Me.oAccessToken = Operations.AuthorizeAsync.Result
End Sub
'
Class Operations
Shared Async Function AuthorizeAsync() As Task(Of SSO.AccessToken)
Dim AccessToken As SSO.AccessToken
Dim AuthorizationCodeTask As Task(Of String)
Dim cts As New System.Threading.CancellationTokenSource
AuthorizationCodeTask = Operations.RunCallbackListenAsync(cts.Token)
Try
OpenAutorizationUrl()
Dim t As String
t = Await AuthorizationCodeTask
AccessToken = GetAccessToken(t)
Catch ex As Exception
logger.LogException(ex)
Throw ex
End Try
Return AccessToken
End Function
Private Shared Async Function RunCallbackListenAsync(ByVal cts As System.Threading.CancellationToken) As Task(Of String)
Dim retval As String = Nothing
Dim blGo As Boolean = True
Dim httpListener As New System.Net.HttpListener
httpListener.Prefixes.Add(My.Settings.APICallBack)
httpListener.AuthenticationSchemes = System.Net.AuthenticationSchemes.Anonymous
httpListener.Start()
If httpListener.IsListening Then
Dim request As System.Net.HttpListenerRequest
Dim context As System.Net.HttpListenerContext
context = Await httpListener.GetContextAsync
While Not cts.IsCancellationRequested And blGo
context = Await httpListener.GetContextAsync
Try
If cts.IsCancellationRequested Then
context.Response.Abort()
End If
request = context.Request
Catch ex As Exception
logger.LogException(ex)
End Try
blGo = False
End While
If Not IsNothing(request) Then
retval = ProcessRequest(request)
Else
Throw New ApplicationException("RunCallbackListenAsync: The request is Nothing")
End If
httpListener.Close()
Else
Throw New ApplicationException("RunCallbackListenAsync: listener is not listening")
End If
Return retval
End Function
End class
what could by causing the blocking at context = Await httpListener.GetContextAsync?
below is a method used to check to see if the Creds entered are good. i also would like to add on to this to see if they are part of group "XXX".
Private Function ValidateActiveDirectoryLogin(ByVal Domain As String, ByVal Username As String, ByVal Password As String) As Boolean
Dim Success As Boolean = False
Dim Entry As New System.DirectoryServices.DirectoryEntry("LDAP://" + Domain, Username, Password)
Dim Searcher As New System.DirectoryServices.DirectorySearcher(Entry)
Searcher.SearchScope = DirectoryServices.SearchScope.OneLevel
Try
Dim Results As System.DirectoryServices.SearchResult = Searcher.FindOne
Success = Not (Results Is Nothing)
Catch ex As Exception
Success = False
End Try
Return Success
End Function
and below i tried to play around with stuff i found on stack but im not having much luck. how can i use existing method and add to it in order to get my results?
Public Function IsInGroup(ByVal UserName As String) As Boolean
'Dim MyIdentity As System.Security.Principal.WindowsIdentity = New WindowsPrincipal(New WindowsIdentity(UserName)) ' System.Security.Principal.WindowsIdentity.GetCurrent()
'Dim userPrincipal = New WindowsPrincipal(New WindowsIdentity(Username))
Dim MyPrincipal As System.Security.Principal.WindowsPrincipal = New WindowsPrincipal(New WindowsIdentity(UserName)) 'New System.Security.Principal.WindowsPrincipal(userPrincipal)
Return MyPrincipal.IsInRole("XXX_YYY")
End Function
Also Tried to do something like this but getting the error i screenshotted.
Public Function IsInGroup(ByVal UserName As String) As Boolean
Dim Result As Boolean
Dim de As New DirectoryEntry("LDAP://AD")
Dim MemberSearcher As New DirectorySearcher
With MemberSearcher
.SearchRoot = de
.Filter = "(&(ObjectClass=Group)(CN=VAL_ITS))"
.PropertiesToLoad.Add("Member")
End With
Dim mySearchResults As SearchResult = MemberSearcher.FindOne()
For Each User In mySearchResults.Properties("Member")
If User = UserName Then
Result = True
Else
Result = False
End If
Next
Return Result
End Function
'Project > Add Reference > System.DirectoryServices.AccountManagement & System.DirectoryServices
Validate using the System.DirectoryServices.AccountManagement namespace
Imports System.DirectoryServices.AccountManagement
Public function validate(username as string, password as string, domain as string)
Dim valid As Boolean = False
Using context As New PrincipalContext(ContextType.Domain, domain)
valid = context.ValidateCredentials(username, password)
End Using
return valid
End Function
Public function checkgroup(domain as string, username as string, groupname as string)
Dim isMember as boolean = false
Dim ctx As New PrincipalContext(ContextType.Domain, domain)
Dim user As UserPrincipal = UserPrincipal.FindByIdentity(ctx, username)
Dim group As GroupPrincipal = GroupPrincipal.FindByIdentity(ctx, groupname)
If user IsNot Nothing Then
If user.IsMemberOf(group) Then
isMember = True
End If
End If
return isMember
End Function
i have the below structure :
this is my controller :
Public Function InsertRegistration() as string
dim res = t.Insertregistration(jsonparam.status)
return res
End Function
this is my class :
Public Function InsertRegistration(byval status as string) as string
sql.Insertregistration(status)
return "1"
End Function
this is my model function :
Public Function InsertRegistration(ByVal status As String) As Boolean
Dim TConnSQL As New SqlConnection(sql)
Dim CommSQL As New SqlClient.SqlCommand("JK_SP_INSERT_PROFILE", TConnSQL)
Dim paramSQL As SqlClient.SqlParameter
Dim data_ada As SqlDataAdapter
Dim dt As DataSet
Try
CommSQL.CommandType = CommandType.StoredProcedure
paramSQL = New SqlClient.SqlParameter("#STATUS", SqlDbType.NVarChar, 100)
paramSQL.Direction = ParameterDirection.Input
paramSQL.Value = STATUS
CommSQL.Parameters.Add(paramSQL)
CommSQL.ExecuteNonQuery()
InsertRegistration= True
Catch ex As System.Data.SqlClient.SqlException
WriteToText("Nbl.InsertRegistration", ex.ToString)
InsertRegistration= False
Catch ex As Exception
WriteToText("Nbl.InsertRegistration", ex.ToString)
InsertRegistration= False
Finally
If (IsNothing(CommSQL) = False) Then CommSQL.Dispose()
If TConnSQL.State <> ConnectionState.Closed Then TConnSQL.Close()
End Try
End Function
is there a way to return the result 1 in an asynchronous way that the function sql.Insertregistration(status) keeps running in background after i return the result to the client?
Simply put your function sql.Insertregistration(status) as in below code:
(new Task<bool>(() =>
{
return sql.Insertregistration(status);
})).Start();
Note: Please take care of the cross thread ooperations.
I cannot seem to get or store the id of the post message I create. I am using this code to post a message:
Try
Dim fb = New FacebookClient(_accessToken)
AddHandler fb.PostCompleted, Function(o, e)
If (e.Cancelled) Then
ElseIf e.Error IsNot Nothing Then
MessageBox.Show(e.Error.Message)
Else
Dim result As Object = e.GetResultData()
_lastMessageId = result.Id
End If
Return MessageBox.Show("Message Posted successfully")
End Function
Dim parameters As Object = New ExpandoObject()
parameters.message = TextBox1.Text
fb.PostTaskAsync("me/feed", parameters)
MsgBox("This is the last message id " & _lastMessageId)
Catch ex As FacebookApiException
MessageBox.Show(ex.Message)
End Try
I just want to store the posted id so I can delete it later.
Here is the working code that i came up with thanks to prabir
Dim fb = New FacebookClient(_accessToken)
Dim parameters As Object = New ExpandoObject()
parameters.message = "Testing"
Dim task = fb.PostTaskAsync("me/feed", parameters)
task.ContinueWith(Function(t)
If t.Exception Is Nothing Then
Dim result As Object = t.Result
_lastMessageId = result.id
Else
MsgBox("error occurred")
End If
Return t.Result
End Function)
here is c# code which might help you get started with it.
Since you are using XTaskAsync methods use ContinueWith instead of PostCompleted.
fb.PostTaskAsync("me/feed", parameters)
.ContinueWith(t= > {
if(!t.IsFaulted) {
dynamic result = t.Result;
}
});
XTaskAsync methods returns Task<object>