I'm developing an iOS application.
Little bit confused about implementing the login module which the (Username/Password, Register and Forgot Password).
New to Couchbase. Used the Couchbase Enterprise Editon "http://192.168.1.126:8091/ui/index.html#/overview" Set up the Couchbase Lite in Xcode and I dunno what's the next step. Does anyone knows?
Data Modeling: Documents JSON
User ("Set as the EMAIL ID")
{
_id:” ",
username::" ",
password::" ",
email::" ",
type:"user"
}
User Info ("Set as the EMAIL ID")
{
_id:” ",
description:" ",
fb_URL::" ",
Twitter::" ",
Gender::" ",
Age::"[min:, max:]",
type:"user"
}
Users can be created in the Sync Gateway configuration file like so:
{
"databases": {
"app": {
"bucket": "walrus",
"users": {
"john": {"password": "pass"}
}
}
}
}
Then, authentication in the iOS app is enabled for this user:
let manager = CBLManager.sharedInstance()
let database = try! manager.databaseNamed("app")
let url = NSURL(string: "http://localhost:4984/app")!
let push = database.createPushReplication(url)
let pull = database.createPullReplication(url)
push.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
pull.authenticator = CBLAuthenticator.basicAuthenticatorWithName("john", password: "pass")
push.start()
pull.start()
For user registration, you'll need to set up an App Server to register users on the Sync Gateway Admin port (4985 by default). To register a user:
$ curl -vX POST -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "pass"}' \
:4985/app/_user/
For the forgotten password functionality, the App Server should update the user record with the new password:
$ curl -vX PUT -H 'Content-Type: application/json' \
-d '{"name": "user2", "password": "newpass"}' \
:4985/app/_user/user2
Related
I have a Jenkins decalarative pipeline where I am calling some URL via cURL which is returning JSON response. How to catch that JSON in a variable?
Have tried the below code but it's returning entire thing with path and command along with the response
environment {
token = bat(returnStdout: true, script: 'curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\\"username\\" : \\"user\\",\\"password\\" : \\"pwd\\"}"').trim()
}
JSON response
C:\ProgramData\Jenkins\.jenkins\workspace\publish-api>curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\"username\" : \"ap-1\",\"password\" : \"Ap5\"}"
{
"access_token": "axxxx-5ca2-48eb-9eb3-173c44a811",
"token_type": "bearer",
"redirectUrl": "/home/"
}
You can use the readJson method to get to your wished result. You don't necesseraly have to call it in your environment-block.
stage('Curl') {
steps {
script {
def cUrlResponse = bat(returnStdout: true, script: '#curl https://anypoint.mulesoft.com/accounts/login -H "Content-Type: application/json" -d "{\\"${env.username}\\" : \\"user\\",\\"${env.password}\\" : \\"pwd\\"}"').trim()
def responseJson = readJSON text: cUrlResponse
def accessToken = responseJson.access_token
def tokenType = responseJson.token_type
// do other stuff with the variables
}
}
}
To exclude the curl command from the output, add # in front of the script as stated in the documentation.
So I'm trying to pass in a string (data) into this sendSlackMessage function but it's not going into the curl command correctly. data is being passed in from my jenkinsfile.
It's working fine in the echo command though.
Can someone tell me what I'm doing wrong?
data = """{'channel': '#mychannel','username': 'jenkins-bot','icon_emoji': ':lol:','text': 'HERERERERE (<$BUILD_URL|Open>)','attachments': [['color': '#36a64f','fields': ['title': 'UPDATING INFOR','value': 'HELLOWORLD','short': 'true']]]}"""
void sendSlackMessage(String data) {
this.steps.sh(returnStdout: true, script: "echo hello world ${data} hello world again")
this.steps.sh(returnStdout: true, script: "curl -X POST -H 'Content-type: application/json' --data '${data}' https://hooks.slack.com/services/T12345671/sdfsdfsdf/sdf7sdf7gsdf")
}
Please try the below implementation
data = """{'channel': '#mychannel','username': 'jenkins-bot','icon_emoji': ':lol:','text': 'HERERERERE (<$BUILD_URL|Open>)','attachments': [['color': '#36a64f','fields': ['title': 'UPDATING INFOR','value': 'HELLOWORLD','short': 'true']]]}"""
void sendSlackMessage(String data) {
List curlCommand = []
curlCommand.add('curl -X POST -H')
curlCommand.add('\'Content-type: application/json\'')
curlCommand.add('--data')
curlCommand.add(data) // Maybe you have to see if you see to add a single quote here and escape it
curlCommand.add('https://hooks.slack.com/services/T12345671')
sh (
returnStdout: true,
script: curlCommand.join(" "),
label: "send slack message"
)
}
There is any way to get all chats from zendesk to website.
I am using zendesk api for get all chats:
curl https://www.zopim.com/api/v2/chats \ -v -u {email_address}:{password}
Here Is my code :
public function getChat_messages(){
$sUrl = "https://www.zopim.com/api/v2/chats";
$authorization = "Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0";
$key= "-v -u email:password";
if (is_resource($rCh = curl_init($sUrl))) {
curl_setopt($rCh, CURLOPT_HTTPHEADER, array('Content-Type: application/json' , 'Authorization: Bearer a362fb582520105c720000631000d6f6f81111f0c95489b9673e722f5c59bf0',
'-v -u email:password',
));
curl_setopt($rCh, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($rCh, CURLOPT_TIMEOUT, 3);
$arrResult = curl_exec($rCh);
$arrResult = explode("\n", $arrResult);
$response = curl_exec($rCh);
$err = curl_error($rCh);
curl_close($rCh);
}
print_r($response);
}
Help will be appreciated..
Thanks.. :)
You did well but there is a little mistake.
$sUrl = "https://www.{your_domain_name}.com/api/v2/chats";
You just copy and paste the line that is why you are getting error.
zopim is not your domain name use your domain name instead of zopim
I am trying to send a post request for the twilio api using swift and Alamofire, but I am having some issues.
This is the function that should send the text:
func sendSMS() {
let parameters = [
"To": "+12036044632",
"From": "+13852322267",
"Body": "Hi daddy"
]
Alamofire.request(.POST, "https://MY SID:MY SECRET#api.twilio.com/2010-04-01/Accounts/MY SID/Messages", parameters: parameters).response { response in
print(response.0)
print(response.1)
print(response.2)
print(response.3)
}
}
When I run this, I get this printed in the console:
`Optional(<NSMutableURLRequest: 0x7a844a30> { URL: https://AC11ed62fdb971a8f56d9be531a5ce40c2:UKCkDN1ojSeT4L27lc8uaNQ5qsvPJgMxd#api.twilio.com/2010-04-01/Accounts/AC11ed62fdb971a8f56d9be531a5ce40c2/Messages })
Optional(<NSHTTPURLResponse: 0x7a9f91f0> { URL: https://AC11ed62fdb971a8f56d9be531a5ce40c2:UKCkDN1oj2SeT4L7lc8uaNQ5qsvPJgMxd#api.twilio.com/2010-04-01/Accounts/AC11ed62fdb971a8f56d9be531a5ce40c2/Messages } { status code: 401, headers {
"Access-Control-Allow-Credentials" = true;
"Access-Control-Allow-Headers" = "Accept, Authorization, Content-Type, If-Match, If-Modified-Since, If-None-Match, If-Unmodified-Since";
"Access-Control-Allow-Methods" = "GET, POST, DELETE, OPTIONS";
"Access-Control-Allow-Origin" = "*";
"Access-Control-Expose-Headers" = ETag;
Connection = "keep-alive";
"Content-Length" = 327;
"Content-Type" = "application/xml";
Date = "Tue, 02 Aug 2016 02:21:01 GMT";
"Twilio-Request-Duration" = "0.004";
"Twilio-Request-Id" = RQ36001aed85114ea18c7eac4f20caaf59;
"Www-Authenticate" = "Basic realm=\"Twilio API\"";
"X-Powered-By" = "AT-5000";
"X-Shenanigans" = none;
} })
Optional(<3c3f786d 6c207665 7273696f 6e3d2731 2e302720 656e636f 64696e67 3d275554 462d3827 3f3e0a3c 5477696c 696f5265 73706f6e 73653e3c 52657374 45786365 7074696f 6e3e3c43 6f64653e 32303030 333c2f43 6f64653e 3c446574 61696c3e 596f7572 20416363 6f756e74 53696420 6f722041 75746854 6f6b656e 20776173 20696e63 6f727265 63742e3c 2f446574 61696c3e 3c4d6573 73616765 3e417574 68656e74 69636174 696f6e20 4572726f 72202d20 4e6f2063 72656465 6e746961 6c732070 726f7669 6465643c 2f4d6573 73616765 3e3c4d6f 7265496e 666f3e68 74747073 3a2f2f77 77772e74 77696c69 6f2e636f 6d2f646f 63732f65 72726f72 732f3230 3030333c 2f4d6f72 65496e66 6f3e3c53 74617475 733e3430 313c2f53 74617475 733e3c2f 52657374 45786365 7074696f 6e3e3c2f 5477696c 696f5265 73706f6e 73653e>)
nil`
I then do not get a text message, and also on the Twilio console, it does not count and does not charge me. Am I getting some kind of error? What am I doing wrong?
Note: I understand the security risks of having the auth in the url, and that is not the fix I am looking for so please do not post or comment about that. Thanks
Instead of:
Alamofire.request(.POST, "https://MY SID:MY SECRET#api.twilio.com/2010-04-01/Accounts/MY SID/Messages", parameters: parameters).response { response in
print(response.0)
print(response.1)
print(response.2)
print(response.3)
}
Try this:
Alamofire.request(.POST, "https://MY SID:MY SECRET#api.twilio.com/2010-04-01/Accounts/MY SID/Messages", parameters: parameters)
.authenticate(user: user, password: password)
.responseJSON { response in
let response = String(response.result.value)
print(response)
}
You have to authenticate correctly into Twilio using Alamofire, and that is what ".authenticate" is for. Change the variable user to your account SID, and change the variable password to your auth token. Reference https://www.twilio.com/console/account/settings to find your account SID and auth token.
You can then manipulate the response string however you'd like.
Hope this helps.
{ status code: 401
It means you're not authenticated. It is possible that your AccountSid or AuthToken was incorrect. If you like to check your credentials, you can try first from your computer with curl and once you get it working you can move to Alamofire.
Example request with curl
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/ACc0966dd96e4d55d26ae72df4d6dc3494/Messages.json' \
--data-urlencode 'To=+16518675309' \
--data-urlencode 'From=+14158141829' \
--data-urlencode 'Body=Hey Jenny! Good luck on the bar exam!' \
-u ACc0966dd96e4d55d26ae72df4d6dc3494:[AuthToken]
docs at https://www.twilio.com/docs/api/rest/sending-messages
My question is along the line of a question which has been asked before at Previous question.
I am using Alamofire 3.2.1, XCode 7.3, iOS9.
Here is my code with the intention to obtain a token from OAuth server (localhost) implemented by django oauth toolkit:
let params = ["grant_type": "password",
"username": "rosa",
"password": "rosa1234"]
let request = Alamofire.request(.POST, url, parameters: params).authenticate(user: __clientID, password: __clientSecret)
debugPrint(request)
request.validate(statusCode: 200..<300)
.validate(contentType: ["application/json"])
.responseSwiftyJSON({ (request, response, json, error) in
debugPrint(response)
if (error != nil) {
print(error.debugDescription)
return completionHandler(token: nil, error: error)
}
// call the completionHandler function (object) to deal with data further
return completionHandler(token: json.string, error: nil)
})
The debug print of request gives a working curl command, which works on a command line:
curl -i \
-X POST \
-u PrtRUN9ra7LHCYWbiReaAjO9I26lJhLhRSAUJgtr:kTvxqKmClDAL3tbdyZdyBZgsfsfXtagMpZyFjSZwpIknxM43l6ZIvJxJGXu2J2FuHf4JMLfopDoAzkF6vHSRq4GZkbnEZSmmUnMvkhMvSucbhWUdzCpxuj9qtc8beaQ3 \
-H "Content-Type: application/x-www-form-urlencoded; charset=utf-8" \
-H "User-Agent: IntelliCafe/xsoft.IntelliCafe (1; OS Version 9.3 (Build 13E230))" \
-H "Accept-Encoding: gzip;q=1.0, compress;q=0.5" \
-H "Accept-Language: en-US;q=1.0" \
-d "grant_type=password&password=rosa1234&username=rosa" \
"http://localhost:8000/o/token/"
But the code does not work in my app. The error is 401:
Optional(<NSHTTPURLResponse: 0x7d183950> { URL: http://localhost:8000/o/token/ } { status code: 401, headers {
"Cache-Control" = "no-store";
"Content-Type" = "application/json";
Date = "Mon, 11 Apr 2016 20:43:48 GMT";
Pragma = "no-cache";
Server = "WSGIServer/0.1 Python/2.7.10";
"X-Frame-Options" = SAMEORIGIN;} })
Optional(Error Domain=com.alamofire.error Code=-6003 "Response status code was unacceptable: 401" UserInfo={NSLocalizedFailureReason=Response status code was unacceptable: 401})
This problem is driving me crazy. Any help will be grateful!
Thanks in advance.
I wrote a django rest view to print out the meta data of the request and found out the clientID and clientSecret are not embedded/processed properly by the django server implementation.
Using the Authorization header as shown in Alamofire documentation works.