Commit ac4618de authored by Pierre SAGASPE's avatar Pierre SAGASPE

plex : store cookies of the basic authentication for if it is recalled

parent 301ea69b
Pipeline #145 failed with stage
in 0 seconds
......@@ -2,7 +2,7 @@
* VLCPlexWebAPI.h
* VLC for iOS
*****************************************************************************
* Copyright (c) 2015 VideoLAN. All rights reserved.
* Copyright (c) 2014-2017 VideoLAN. All rights reserved.
*
* Authors: Pierre Sagaspe <pierre.sagaspe # me.com>
*
......
......@@ -2,7 +2,7 @@
* VLCPlexWebAPI.m
* VLC for iOS
*****************************************************************************
* Copyright (c) 2014-2015 VideoLAN. All rights reserved.
* Copyright (c) 2014-2017 VideoLAN. All rights reserved.
*
* Authors: Pierre Sagaspe <pierre.sagaspe # me.com>
*
......@@ -24,8 +24,13 @@
- (NSArray *)PlexBasicAuthentification:(NSString *)username password:(NSString *)password
{
NSArray *authToken = nil;
NSURL *url = [NSURL URLWithString:kPlexMediaServerSignIn];
NSArray *cookies = [[NSHTTPCookieStorage sharedHTTPCookieStorage] cookiesForURL:url];
if ([cookies count])
return cookies;
NSString *authString = [NSString stringWithFormat:@"%@:%@", username, password];
NSData *authData = [authString dataUsingEncoding:NSASCIIStringEncoding];
NSString *authBase64 = [NSString stringWithFormat:@"Basic %@", [authData base64EncodedStringWithOptions:0]];
......@@ -42,6 +47,7 @@
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
authToken = [NSHTTPCookie cookiesWithResponseHeaderFields:[response allHeaderFields] forURL:[NSURL URLWithString:@""]];
[[NSHTTPCookieStorage sharedHTTPCookieStorage] setCookies:authToken forURL:url mainDocumentURL:nil];
return authToken;
}
......@@ -289,4 +295,4 @@
return data;
}
@end
\ No newline at end of file
@end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment