Faraday: Faraday.get und grundlegende Authentifizierung

Erstellt am 23. Okt. 2014  ·  5Kommentare  ·  Quelle: lostisland/faraday

I can't seem to get Faraday.get to accept the user:pass@host syntax from a url and respect it. Ich kann Faraday.get anscheinend nicht dazu bringen, die user:pass@host -Syntax von einer URL zu akzeptieren und zu respektieren.

Reproducing with Faraday 0.9.0 Reproduzieren mit Faraday 0.9.0

Faraday.get("http://foo:bar<strong i="9">@localhost</strong>:3333/test")

The "server" Der Kellner"

% nc -l localhost 3333
GET /test HTTP/1.1
User-Agent: Faraday v0.9.0
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: localhost:3333

I expected an Authentication header, or perhaps an error that auth wasn't supported. Ich habe einen Authentication-Header erwartet oder vielleicht einen Fehler, dass auth nicht unterstützt wird.

I couldn't find docs on the Faraday.get method on rubydoc.info for the Faraday module: http://www.rubydoc.info/gems/faraday/Faraday - so I'm not sure what I'm doing wrong. Ich konnte keine Dokumente zur Faraday.get -Methode auf rubydoc.info für das Faraday-Modul finden: http://www.rubydoc.info/gems/faraday/Faraday - also bin ich mir nicht sicher, was ich bin falsch machen.

If you point me in the write direction, I am happy to write documentation for this method. Wenn Sie mich in die Schreibrichtung verweisen, schreibe ich gerne eine Dokumentation für diese Methode.

en

Hilfreichster Kommentar

einfacher:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en

Alle 5 Kommentare

There are several ways you can set authentication headers with Faraday. Es gibt mehrere Möglichkeiten, wie Sie Authentifizierungsheader mit Faraday festlegen können. One way is to initialize a Faraday::Connection instance and use the basic_auth helper method: Eine Möglichkeit besteht darin, eine Faraday::Connection -Instanz zu initialisieren und die basic_auth zu verwenden:

conn = Faraday.new(url: 'http://example.com') # create a new Connection with base URL
conn.basic_auth('user', 'pass')               # set the Authentication header
conn.get('/foo')                              # GET http://example.com/foo

You could also use middleware: Sie können auch Middleware verwenden:

conn = Faraday.new(url: 'http://example.com') do |builder|
  builder.use Faraday::Request::Retry
  builder.use Faraday::Request::BasicAuthentication, 'user', 'pass'
  builder.use Faraday::Response::Logger
  builder.use Faraday::Adapter::NetHttp
end

conn.get('/foo')

or: oder:

Faraday.new(url: 'http://example.com') do |builder|
  builder.request  :retry
  builder.request  :basic_authentication, 'user', 'pass'
  builder.response :logger
  builder.adapter  :net_http
end

conn.get('/foo')

Intridea has a nice blog post on basic Faraday usage that's a few years old but still relevant. Intridea hat einen netten Blogbeitrag über die grundlegende Verwendung von Faraday , der ein paar Jahre alt, aber immer noch relevant ist.

Hope it helps some, Hoffe es hilft einigen,
OI OI

en

Thanks @OI for the helpful examples. Danke @OI für die hilfreichen Beispiele.

@jordansissel For now, please use this form: @jordansissel Verwenden Sie vorerst bitte dieses Formular:

conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass')
conn.get('/foo')

Sorry for the trouble. Entschuldigung für die Probleme.

en

Thanks for the pointers, all! Danke für die Hinweise, alle! It helped me get things working. Es hat mir geholfen, die Dinge zum Laufen zu bringen. ❤️❤️❤️ ❤️❤️❤️

On Tuesday, October 6, 2015, Mislav Marohnić [email protected] Am Dienstag, 6. Oktober 2015, Mislav Marohnić [email protected]
wrote: schrieb:

Thanks @OI https://github.com/OI for the helpful examples. Danke @OI https://github.com/OI für die hilfreichen Beispiele.

@jordansissel https://github.com/jordansissel For now, please use this @jordansissel https://github.com/jordansissel Verwenden Sie vorerst bitte dies
form: form:

conn = Faraday.new('http://example.com') conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass') conn.basic_auth('user', 'pass')
conn.get('/foo') conn.get('/foo')

Sorry for the trouble. Entschuldigung für die Probleme.


Reply to this email directly or view it on GitHub Antworten Sie direkt auf diese E-Mail oder zeigen Sie sie auf GitHub an
https://github.com/lostisland/faraday/issues/426#issuecomment -145914646. https://github.com/lostisland/faraday/issues/426#issuecomment -145914646.

en

Dies wurde auch als #343 gemeldet.

en

einfacher:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en
War diese Seite hilfreich?
0 / 5 - 0 Bewertungen