0

Im trying to port an app from iOS to java but the docs are pretty broken, I was given a sample bit of code that is used to authenticate the user.

"To authentication, the HTTP Header "Authorization" must be set with the value "Basic base64encodedValue" where base64encodedValue is the string of "email:password" (the user's email and password) encoded in base 64. The authorization call in objective-c looks like the following:"

- (void)setAuthorizationHeaderFieldWithUsername:(NSString *)username password:(NSString *)

password {

NSString *basicAuthCredentials = [NSString stringWithFormat:@"%@:%@", username, password];

[self setValue:[NSString stringWithFormat:@"Basic %@", 

AFBase64EncodedStringFromString(basicAuthCredentials)] forHTTPHeaderField:@"Authorization"];

}

Returns authentication_token - This token needs to be supplied to the methods in the HTTP Header "Authorization""

The wording is strange so is this just adding a generic header to the http request? is the key for the header request "Authorization" with a value of the base64 encoded "username:password"

or is the key actually "Basic base64encodedValue" ?

or is it actually sending basic authenitcation with the request?

TheAmateurProgrammer
  • 9,252
  • 8
  • 52
  • 71
Brian
  • 4,328
  • 13
  • 58
  • 103
  • This might help with working with Base64 string; http://stackoverflow.com/questions/19743851/base64-java-encode-and-decode-a-string My guess is it's setting the Authorization header with a base64 encoded value which is the value of "email:password". The heard is sent with the HTTP request. – Doswell Jul 25 '14 at 21:57
  • I know how to base64 encode a string, im asking what headers is this code snippet adding to the request – Brian Jul 25 '14 at 22:02

1 Answers1

1

It adds the concatenation of 'Basic ' and the base64 value of email:password, where email and password are specific to each user.

In a simple pseudocode, the header is formed like this:

header = 'Basic ' + base64(email:password)

That is the value. The key is 'Authorization'

  • Ok, I see that makes sense, they used too many quotes I couldn't tell what was supposed to be a literal string. One last thing is AFBase64EncodedStringFromString in any way different than any other base64 encoding scheme. Will it be the same as java, php, etc?? – Brian Jul 25 '14 at 22:17
  • Don't know, I never used it personally. But I expect it's the same. – Marius Constantinescu Jul 25 '14 at 22:20