How to get the user's country calling code in iOS? - iphone

I am developing an iOS app in which the user enters their mobile number. How do I get their country calling code? For example, if a user is in India, then +91 should be prefixed automatically. Is there an option that adds country codes automatically?

Import Statement :
#import<CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
you can get country code for the current Carrier using CoreTelephony framework:
CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;
NSLog(#"country code is: %#", carrier.mobileCountryCode);
//will return the actual country code
NSLog(#"ISO country code is: %#", carrier.isoCountryCode);
Apple Docs

with the use of NSLocale you can get the country name, code etc. Take a look at below code it will help you to do so.
NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode]; // get country code, e.g. ES (Spain), FR (France), etc.
for a countries dialing code you can visit this reference code.

Use this simple function
func getCountryCallingCode(countryRegionCode:String)->String{
let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"]
let countryDialingCode = prefixCodes[countryRegionCode]
return countryDialingCode!
}
And call as
let currentLocale = NSLocale.currentLocale()
let countryCode = currentLocale.objectForKey(NSLocaleCountryCode) as! String//get the set country name, code of your iphone
print("country code is \(countryCode)")
print(getCountryCallingCode(countryCode))
//change country region Settings>>General>>Language&Region>>Region

Swift
let networkInfo = CTTelephonyNetworkInfo()
if let carrier = networkInfo.subscriberCellularProvider {
print("country code is: " + carrier.mobileCountryCode!);
//will return the actual country code
print("ISO country code is: " + carrier.isoCountryCode!);
}

Swift 5
I combine answer from Oded and LC into a function.
func getCountryCode() -> String {
guard let carrier = CTTelephonyNetworkInfo().subscriberCellularProvider, let countryCode = carrier.isoCountryCode else { return "" }
let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"]
let countryDialingCode = prefixCodes[countryCode.uppercased()] ?? ""
return countryDialingCode
}
Make sure to import CoreTelephony at the top
import CoreTelephony

I think you need to use NSLocale for using Country code of the user.
You can follow this link to understand use of NSLocale class reference.
Also study this link for ISOCountryCode property.
Hope this may help you.

I came up with the following code, based on previous answers:
Swift
#if canImport(CoreTelephony)
import CoreTelephony
#endif
static func getRegionCodeFromSim() -> String? {
#if canImport(CoreTelephony)
let networkInfos = CTTelephonyNetworkInfo()
if #available(iOS 12, *) {
let carrier = networkInfos.serviceSubscriberCellularProviders?
.map { $0.1 }
.first { $0.isoCountryCode != nil }
return carrier?.isoCountryCode
}
return networkInfos.subscriberCellularProvider?.isoCountryCode
#else
return nil
#endif
}
static func getRegionCode() -> String? {
guard let regionCodeFromSim = Self.getRegionCodeFromSim() else {
return NSLocale.current.regionCode
}
return regionCodeFromSim
}
static func getCountryCode() -> String? {
guard let regionCode = Self.getRegionCode() else { return nil }
let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"]
return prefixCodes[regionCode.uppercased()]
}
It tries to fetch the country code from the SIM cards (with multi-sim & non-sim devices support), if available, and fallbacks to the device's locale otherwise.
The prefixCodes could be loaded from a PLIST or JSON to help with readability.

If you want to prefixed calling country code automatically
then you need to get user's country code pragmatically and Drag & drop src Folder in your code
Its looks like this:
if let countryCode = (Locale.current as NSLocale).object(forKey: .countryCode) as? String {
print(countryCode)
let strCode = Countries.countryFromCountryCode(countryCode: countryCode)
btnPhoneCode.setTitle("+\(strCode.phoneExtension)", for: .normal)
}
It works for me, Hope will help you too. :)

NSLocale *currentLocale = [NSLocale currentLocale]; // get the current locale.
NSString *countryCode = [currentLocale objectForKey:NSLocaleCountryCode];
// get country code, e.g. ES (Spain), FR (France), etc.
NSLog(#"country code is:%#",countryCode);
NSString*lower=[countryCode lowercaseString];
NSString *path = [[NSBundle mainBundle] pathForResource:#"DiallingCodes" ofType:#"plist"];
NSDictionary *dict = [[NSDictionary alloc] initWithContentsOfFile:path];
NSMutableDictionary *_dictCountry=[[NSMutableDictionary alloc]init];
NSMutableArray *_CodeArray=[[NSMutableArray alloc]init];
[_CodeArray addObject:dict];
_dictCountry = [_CodeArray objectAtIndex:0];
NSString*Country_code=[NSString stringWithFormat:#"+%#",[_dictCountry objectForKey:lower]];
contactTextField.text=Country_code;

You can request to this url.
For get CountryCode or ip, region_name, city, long, lat
NSURLRequest *request = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:#"http://freegeoip.net/json/"]];
__block NSDictionary *json;
[NSURLConnection sendAsynchronousRequest:request
queue:[NSOperationQueue mainQueue]
completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
NSLog(#"Countrycode: %#", json[#"country_code"]);
}];

Here the Objective C code
#import<CoreTelephony/CTCarrier.h>
#import <CoreTelephony/CTTelephonyNetworkInfo.h>
- (void)viewDidLoad{
CTTelephonyNetworkInfo *network_Info = [CTTelephonyNetworkInfo new];
CTCarrier *carrier = network_Info.subscriberCellularProvider;
NSLog(#"country code is: %#", carrier.mobileCountryCode);
NSLog(#"ISO country code is: %#", carrier.mobileNetworkCode);
NSLog(#"diling code == %#",[self getCountryCode:carrier.isoCountryCode]);
}
- (NSString *)getCountryCode:(NSString *)countryISOCode{
NSDictionary * code = #{#"AF": #"93", #"AE": #"971", #"AL": #"355", #"AN": #"599", #"AS":#"1", #"AD": #"376", #"AO": #"244", #"AI": #"1", #"AG":#"1", #"AR": #"54",#"AM": #"374", #"AW": #"297", #"AU":#"61", #"AT": #"43",#"AZ": #"994", #"BS": #"1", #"BH":#"973", #"BF": #"226",#"BI": #"257", #"BD": #"880", #"BB": #"1", #"BY": #"375", #"BE":#"32",#"BZ": #"501", #"BJ": #"229", #"BM": #"1", #"BT":#"975", #"BA": #"387", #"BW": #"267", #"BR": #"55", #"BG": #"359", #"BO": #"591", #"BL": #"590", #"BN": #"673", #"CC": #"61", #"CD":#"243",#"CI": #"225", #"KH":#"855", #"CM": #"237", #"CA": #"1", #"CV": #"238", #"KY":#"345", #"CF":#"236", #"CH": #"41", #"CL": #"56", #"CN":#"86",#"CX": #"61", #"CO": #"57", #"KM": #"269", #"CG":#"242", #"CK": #"682", #"CR": #"506", #"CU":#"53", #"CY":#"537",#"CZ": #"420", #"DE": #"49", #"DK": #"45", #"DJ":#"253", #"DM": #"1", #"DO": #"1", #"DZ": #"213", #"EC": #"593", #"EG":#"20", #"ER": #"291", #"EE":#"372",#"ES": #"34", #"ET": #"251", #"FM": #"691", #"FK": #"500", #"FO": #"298", #"FJ": #"679", #"FI":#"358", #"FR": #"33", #"GB":#"44", #"GF": #"594", #"GA":#"241", #"GS": #"500", #"GM":#"220", #"GE":#"995",#"GH":#"233", #"GI": #"350", #"GQ": #"240", #"GR": #"30", #"GG": #"44", #"GL": #"299", #"GD":#"1", #"GP": #"590", #"GU": #"1", #"GT": #"502", #"GN":#"224",#"GW": #"245", #"GY": #"595", #"HT": #"509", #"HR": #"385", #"HN":#"504", #"HU": #"36", #"HK": #"852", #"IR": #"98", #"IM": #"44", #"IL": #"972", #"IO":#"246", #"IS": #"354", #"IN": #"91", #"ID":#"62", #"IQ":#"964", #"IE": #"353",#"IT":#"39", #"JM":#"1", #"JP": #"81", #"JO": #"962", #"JE":#"44", #"KP": #"850", #"KR": #"82",#"KZ":#"77", #"KE": #"254", #"KI": #"686", #"KW": #"965", #"KG":#"996",#"KN":#"1", #"LC": #"1", #"LV": #"371", #"LB": #"961", #"LK":#"94", #"LS": #"266", #"LR":#"231", #"LI": #"423", #"LT": #"370", #"LU": #"352", #"LA": #"856", #"LY":#"218", #"MO": #"853", #"MK": #"389", #"MG":#"261", #"MW": #"265", #"MY": #"60",#"MV": #"960", #"ML":#"223", #"MT": #"356", #"MH": #"692", #"MQ": #"596", #"MR":#"222", #"MU": #"230", #"MX": #"52",#"MC": #"377", #"MN": #"976", #"ME": #"382", #"MP": #"1", #"MS": #"1", #"MA":#"212", #"MM": #"95", #"MF": #"590", #"MD":#"373", #"MZ": #"258", #"NA":#"264", #"NR":#"674", #"NP":#"977", #"NL": #"31",#"NC": #"687", #"NZ":#"64", #"NI": #"505", #"NE": #"227", #"NG": #"234", #"NU":#"683", #"NF": #"672", #"NO": #"47",#"OM": #"968", #"PK": #"92", #"PM": #"508", #"PW": #"680", #"PF": #"689", #"PA": #"507", #"PG":#"675", #"PY": #"595", #"PE": #"51", #"PH": #"63", #"PL":#"48", #"PN": #"872",#"PT": #"351", #"PR": #"1",#"PS": #"970", #"QA": #"974", #"RO":#"40", #"RE":#"262", #"RS": #"381", #"RU": #"7", #"RW": #"250", #"SM": #"378", #"SA":#"966", #"SN": #"221", #"SC": #"248", #"SL":#"232",#"SG": #"65", #"SK": #"421", #"SI": #"386", #"SB":#"677", #"SH": #"290", #"SD": #"249", #"SR": #"597",#"SZ": #"268", #"SE":#"46", #"SV": #"503", #"ST": #"239",#"SO": #"252", #"SJ": #"47", #"SY":#"963", #"TW": #"886", #"TZ": #"255", #"TL": #"670", #"TD": #"235", #"TJ": #"992", #"TH": #"66", #"TG":#"228", #"TK": #"690", #"TO": #"676", #"TT": #"1", #"TN":#"216",#"TR": #"90", #"TM": #"993", #"TC": #"1", #"TV":#"688", #"UG": #"256", #"UA": #"380", #"US": #"1", #"UY": #"598",#"UZ": #"998", #"VA":#"379", #"VE":#"58", #"VN": #"84", #"VG": #"1", #"VI": #"1",#"VC":#"1", #"VU":#"678", #"WS": #"685", #"WF": #"681", #"YE": #"967", #"YT": #"262",#"ZA": #"27" , #"ZM": #"260", #"ZW":#"263"};
return [NSString stringWithFormat:#"+%#", [code objectForKey:[countryISOCode uppercaseString]]];
}

Swift 5 Support and using optionals here is my solution:
static func GetCountryCallingCode(countryRegionCode:String) -> String? {
let prefixCodes = ["AF": "93", "AE": "971", "AL": "355", "AN": "599", "AS":"1", "AD": "376", "AO": "244", "AI": "1", "AG":"1", "AR": "54","AM": "374", "AW": "297", "AU":"61", "AT": "43","AZ": "994", "BS": "1", "BH":"973", "BF": "226","BI": "257", "BD": "880", "BB": "1", "BY": "375", "BE":"32","BZ": "501", "BJ": "229", "BM": "1", "BT":"975", "BA": "387", "BW": "267", "BR": "55", "BG": "359", "BO": "591", "BL": "590", "BN": "673", "CC": "61", "CD":"243","CI": "225", "KH":"855", "CM": "237", "CA": "1", "CV": "238", "KY":"345", "CF":"236", "CH": "41", "CL": "56", "CN":"86","CX": "61", "CO": "57", "KM": "269", "CG":"242", "CK": "682", "CR": "506", "CU":"53", "CY":"537","CZ": "420", "DE": "49", "DK": "45", "DJ":"253", "DM": "1", "DO": "1", "DZ": "213", "EC": "593", "EG":"20", "ER": "291", "EE":"372","ES": "34", "ET": "251", "FM": "691", "FK": "500", "FO": "298", "FJ": "679", "FI":"358", "FR": "33", "GB":"44", "GF": "594", "GA":"241", "GS": "500", "GM":"220", "GE":"995","GH":"233", "GI": "350", "GQ": "240", "GR": "30", "GG": "44", "GL": "299", "GD":"1", "GP": "590", "GU": "1", "GT": "502", "GN":"224","GW": "245", "GY": "595", "HT": "509", "HR": "385", "HN":"504", "HU": "36", "HK": "852", "IR": "98", "IM": "44", "IL": "972", "IO":"246", "IS": "354", "IN": "91", "ID":"62", "IQ":"964", "IE": "353","IT":"39", "JM":"1", "JP": "81", "JO": "962", "JE":"44", "KP": "850", "KR": "82","KZ":"77", "KE": "254", "KI": "686", "KW": "965", "KG":"996","KN":"1", "LC": "1", "LV": "371", "LB": "961", "LK":"94", "LS": "266", "LR":"231", "LI": "423", "LT": "370", "LU": "352", "LA": "856", "LY":"218", "MO": "853", "MK": "389", "MG":"261", "MW": "265", "MY": "60","MV": "960", "ML":"223", "MT": "356", "MH": "692", "MQ": "596", "MR":"222", "MU": "230", "MX": "52","MC": "377", "MN": "976", "ME": "382", "MP": "1", "MS": "1", "MA":"212", "MM": "95", "MF": "590", "MD":"373", "MZ": "258", "NA":"264", "NR":"674", "NP":"977", "NL": "31","NC": "687", "NZ":"64", "NI": "505", "NE": "227", "NG": "234", "NU":"683", "NF": "672", "NO": "47","OM": "968", "PK": "92", "PM": "508", "PW": "680", "PF": "689", "PA": "507", "PG":"675", "PY": "595", "PE": "51", "PH": "63", "PL":"48", "PN": "872","PT": "351", "PR": "1","PS": "970", "QA": "974", "RO":"40", "RE":"262", "RS": "381", "RU": "7", "RW": "250", "SM": "378", "SA":"966", "SN": "221", "SC": "248", "SL":"232","SG": "65", "SK": "421", "SI": "386", "SB":"677", "SH": "290", "SD": "249", "SR": "597","SZ": "268", "SE":"46", "SV": "503", "ST": "239","SO": "252", "SJ": "47", "SY":"963", "TW": "886", "TZ": "255", "TL": "670", "TD": "235", "TJ": "992", "TH": "66", "TG":"228", "TK": "690", "TO": "676", "TT": "1", "TN":"216","TR": "90", "TM": "993", "TC": "1", "TV":"688", "UG": "256", "UA": "380", "US": "1", "UY": "598","UZ": "998", "VA":"379", "VE":"58", "VN": "84", "VG": "1", "VI": "1","VC":"1", "VU":"678", "WS": "685", "WF": "681", "YE": "967", "YT": "262","ZA": "27" , "ZM": "260", "ZW":"263"]
let countryDialingCode = prefixCodes[countryRegionCode]
return countryDialingCode
}
guard let regionCode = NSLocale.current.regionCode,
let callingCode = GetCountryCallingCode(countryRegionCode: regionCode )
else { return }
print("Region: \(regionCode) Country calling code is \(callingCode)")

import CoreTelephony
/// Method to get the iso calling code
///
/// - Returns: String
public static func getCallingCodePrefix() -> String {
let networkInfo = CTTelephonyNetworkInfo()
let phoneNumberKit = PhoneNumberKit()
if #available(iOS 12.0, *) {
if let carrier = networkInfo.serviceSubscriberCellularProviders?.map({ $0.1 }).first(where: { $0.isoCountryCode != nil }), let isoCode = carrier.isoCountryCode?.uppercased(), let prefixCode = phoneNumberKit.countryCode(for: isoCode) {
return "+" + String(prefixCode)
}
} else {
// Fallback on earlier versions
if let carrier = networkInfo.subscriberCellularProvider, let isoCode = carrier.isoCountryCode?.uppercased(), let prefixCode = phoneNumberKit.countryCode(for: isoCode) {
return "+" + String(prefixCode)
}
}
return "+"
}

Use this code to get the user's country in iOS:
func countryName(from countryCode: String) -> String {
if let name = (Locale.current as NSLocale).displayName(forKey: .countryCode, value: countryCode) {
return name
} else {
return countryCode
}
}
//Locale.current.regionCode this is used for Get user current country region code
countryName(from: Locale.current.regionCode ?? "")

Related

Uncaught Error: TypeError: null: type 'JSNull' is not a subtype of type 'List<dynamic>'

I'm looking for a way to copy the values in the category_name field to a list without using the add operator. The idea behind not using the add operator is to prevent the existing data from remaining in the list. For example, if in a newer JSON data set, the values in category_name are [xyz, food] & [efg, food], then I intend to print [xyz, efg] instead of [Veg, Veg, NonVeg, XYZ, efg].
Please note that the JSON data currently assigned to duplicates is meant to be dynamic which is why it is important for me to find a solution in which I can only assign the values in category_name from the current JSON data set which is meant to change with API calls.
void main() {
List<dynamic> list = [];
Map<String, dynamic> duplicates = {
"status": "success",
"data": [
{
"product_id": 17,
"category_name": [
"Veg",
"Dinner"
],
"restaurant_name": "Mocambo",
"product_name": "Panner Makhani",
"product_description": "Mouth Smacking Creamy Indian Gravy.",
"product_image": "/assets/product/WOw4Rc03-02-08.jpg",
"product_selling_price": "240",
"product_status": "active",
"product_quantity": "50",
"product_rating": "",
"product_rating_count": "",
"product_sell_count": "0"
},
{
"product_id": 16,
"category_name": [
"Veg",
"Dinner"
],
"restaurant_name": "Mocambo",
"product_name": "Panner Makhani",
"product_description": "Mouth Smacking Creamy Indian Gravy.",
"product_image": "/assets/product/WOw4Rc03-02-08.jpg",
"product_selling_price": "240",
"product_status": "active",
"product_quantity": "50",
"product_rating": "",
"product_rating_count": "",
"product_sell_count": "0"
},
{
"product_id": 15,
"category_name": [
"NonVeg",
"Snacks"
],
"restaurant_name": "Mocambo",
"product_name": "Cheese Steak Burger",
"product_description": "Tasty steak burger oozing with the goodness of creamy cheese",
"product_image": "/assets/product/SBuZnx02-54-20.jpg",
"product_selling_price": "150",
"product_status": "active",
"product_quantity": "20",
"product_rating": "",
"product_rating_count": "",
"product_sell_count": "0"
}
]
};
list = duplicates['data'].forEach((value) => value["category_name"][0]);
print(list);
}
I tried doing list = duplicates['data'].forEach((value) => value["category_name"][0]); thinking that everytime the JSON data in duplicates changes, the previous values will get overwritten with new ones. But it doesn't really work that way because of the above error. Any help will be appreciated.

Factory Unhandled Exception: type '(dynamic) => DataAd' is not a subtype of type '(String, dynamic)

I have trying to figure out in some question but there is no case like me. I am getting the code from tutorial and I have understand it. However, the problem is in the tutorial. It uses static JSON (list) where mine using dynamic which contain keys.
Here is my code
class CompileAd {
String status;
String notification;
Map<int,DataAd> adData;
CompileAd({
required this.status,
required this.notification,
required this.adData,
});
factory CompileAd.fromJson(Map<String, dynamic> json) => CompileAd(
status: json["status"],
notification: json["notification"],
adData: Map<int,DataAd>.from(
json["adData"].map((x) => DataAd.fromJson(x))), => ERROR HERE
);
Map<String, dynamic> toJson() => {
"status": status,
"notification": notification,
"adData": Map<dynamic,dynamic>.from(adData.map((key,x) => x.toJson())), => HERE ALSO (Actually, I wish to use "jsonEncode(adData)" since its working but no idea which one better)
};
}
Error Log
lib/class/adClass.dart:27:69: Error: A value of type 'Map<String,
dynamic>' can't be returned from a function with return type
'MapEntry<dynamic, dynamic>'.
'Map' is from 'dart:core'.
'MapEntry' is from 'dart:core'.
"adData": Map<dynamic,dynamic>.from(adData.map((key,x) => x.toJson())),
^
Here is the json object
adData => (keyID,adObject)
{
"adData": {
"77289": {
"id": 77289,
"username": "magdatjahja#gmail.com",
"category": "rumah",
"subCategory": "rumah",
"type": "dijual",
"uniqueId": "6436",
"title": "Jual Rumah di Mazenta Bintaro Tangerang Selatan",
"slug": "jual-rumah-di-mazenta-bintaro-tangerang-selatan",
"content": "Jual rumah di mazento bintaro tangerang selatan\r\n\r\nSatu-satunya hunian premium di kawasan Bintaro bernuansa Japan Ambiance Living :\r\n\r\nType unit :\r\n\ud83d\udc49 Type 6 \r\nLuas Tanah: 72m2 \r\nLuas Bangunan: 83m2 \r\nKamar Tidur: 3 \r\nKamar Mandi: 2 \r\n\r\n\ud83c\udf81Dapatkan Promo Early Bird Price !!!\ud83c\udf81\r\n\u2705HARGA MULAI RP.1,8 M\r\n\u27053 unit AC 1 Pk\r\n\u2705Free Mini Canopy\r\n\u2705 Lucky Bowl up to Iphone13\r\n\u2705 SmartDoorlock\r\n\r\nLokasi\r\n\ud83d\ude97 Hanya 3 menit ke BXchange Mall Bintaro!\r\n\ud83d\ude97 Hanya 2-3 menit ke pintu tol! dan jumlah unit SANGAT terbatas!\r\n\ud83d\ude97Hanya 3 Menit Statiun Jurang Mangu\r\n\ud83d\ude97Hanya 3 menit UPJ University\r\n\r\n\r\nHubungi AGENT MERKETING\r\nMagda 08118897878",
"bid": 2000,
"balance": 1,
"price": "1800000000",
"province": "banten",
"regency": "tangerang selatan",
"district": "",
"village": "",
"complex": "",
"rd": 1,
"premier": "2022-03-22 11:33:13",
"partner": 1,
"privateSync": "0000-00-00 00:00:00",
"penaltyTime": null,
"data": {
"price": {
"price": "1800000000"
},
"priceUnit": "",
"province": "banten",
"regency": "tangerang selatan",
"district": "",
"village": "",
"additional": {
"address": "Bintaro, Tangerang Selatan",
"complex": "",
"lt": "72",
"lb": "83",
"bedroom": "3",
"bathroom": "2",
"maidbedroom": "",
"maidbathroom": "",
"floor": "",
"garage": "",
"carports": "",
"electricity": "",
"orientation": "",
"interior": ""
},
"facebook": "2022-03-22 14:54:05",
"twitter": "0000-00-00 00:00:00",
"pinterest": "0000-00-00 00:00:00",
"tumblr": "0000-00-00 00:00:00",
"premier": "2022-03-22 11:33:13",
"partner": true,
"penaltyTime": "2022-03-22 11:32:01",
"instagram": "2022-03-22 14:47:14"
},
"images": {
"images": ["jual-rumah-di-mazenta-bintaro-tangerang-selatan-0XOV3B.jpg", "jual-rumah-di-mazenta-bintaro-tangerang-selatan-VS38QN.jpg", "jual-rumah-di-mazenta-bintaro-tangerang-selatan-14RHI3.jpg"],
"imagesAdditional": [],
"images360": []
},
"video": {
"1": "https:\/\/youtu.be\/CA6iNWEDa1E"
},
"sosmed": 0,
"view": 28,
"contact": 0,
"status": "active",
"checked": 1,
"sold": "0000-00-00 00:00:00",
"modify": "0000-00-00 00:00:00",
"waktu": "2022-03-21 17:40:03",
"dir": "\/uploads\/images\/2022\/03\/77289\/",
"url": "\/properti\/tangerang-selatan\/6436-jual-rumah-di-mazenta-bintaro-tangerang-selatan\/"
}
},
"status": "success",
"notification": "Berhasil memproses permintaan"
}
I really appreciate any answers. Thank you.

How to get the Social preview of a github project?

I could get the project, but it does not retrieve the Social Preview of the project:
The link that I'm using is this one:
https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD
which is returning the following:
{
"id": 215636067,
"node_id": "MDEwOlJlcG9zaXRvcnkyMTU2MzYwNjc=",
"name": "BCMIC-PHD",
"full_name": "AngelRibeiro10/BCMIC-PHD",
"private": false,
"owner": {
"login": "AngelRibeiro10",
"id": 13433634,
"node_id": "MDQ6VXNlcjEzNDMzNjM0",
"avatar_url": "https://avatars2.githubusercontent.com/u/13433634?v=4",
"gravatar_id": "",
"url": "https://api.github.com/users/AngelRibeiro10",
"html_url": "https://github.com/AngelRibeiro10",
"followers_url": "https://api.github.com/users/AngelRibeiro10/followers",
"following_url": "https://api.github.com/users/AngelRibeiro10/following{/other_user}",
"gists_url": "https://api.github.com/users/AngelRibeiro10/gists{/gist_id}",
"starred_url": "https://api.github.com/users/AngelRibeiro10/starred{/owner}{/repo}",
"subscriptions_url": "https://api.github.com/users/AngelRibeiro10/subscriptions",
"organizations_url": "https://api.github.com/users/AngelRibeiro10/orgs",
"repos_url": "https://api.github.com/users/AngelRibeiro10/repos",
"events_url": "https://api.github.com/users/AngelRibeiro10/events{/privacy}",
"received_events_url": "https://api.github.com/users/AngelRibeiro10/received_events",
"type": "User",
"site_admin": false
},
"html_url": "https://github.com/AngelRibeiro10/BCMIC-PHD",
"description": "This is a Brain-Computer Music Interfacing Project",
"fork": false,
"url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD",
"forks_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/forks",
"keys_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/keys{/key_id}",
"collaborators_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/collaborators{/collaborator}",
"teams_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/teams",
"hooks_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/hooks",
"issue_events_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/issues/events{/number}",
"events_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/events",
"assignees_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/assignees{/user}",
"branches_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/branches{/branch}",
"tags_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/tags",
"blobs_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/git/blobs{/sha}",
"git_tags_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/git/tags{/sha}",
"git_refs_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/git/refs{/sha}",
"trees_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/git/trees{/sha}",
"statuses_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/statuses/{sha}",
"languages_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/languages",
"stargazers_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/stargazers",
"contributors_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/contributors",
"subscribers_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/subscribers",
"subscription_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/subscription",
"commits_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/commits{/sha}",
"git_commits_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/git/commits{/sha}",
"comments_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/comments{/number}",
"issue_comment_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/issues/comments{/number}",
"contents_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/contents/{+path}",
"compare_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/compare/{base}...{head}",
"merges_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/merges",
"archive_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/{archive_format}{/ref}",
"downloads_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/downloads",
"issues_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/issues{/number}",
"pulls_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/pulls{/number}",
"milestones_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/milestones{/number}",
"notifications_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/notifications{?since,all,participating}",
"labels_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/labels{/name}",
"releases_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/releases{/id}",
"deployments_url": "https://api.github.com/repos/AngelRibeiro10/BCMIC-PHD/deployments",
"created_at": "2019-10-16T20:14:22Z",
"updated_at": "2019-11-14T16:52:13Z",
"pushed_at": "2019-11-14T16:52:11Z",
"git_url": "git://github.com/AngelRibeiro10/BCMIC-PHD.git",
"ssh_url": "git#github.com:AngelRibeiro10/BCMIC-PHD.git",
"clone_url": "https://github.com/AngelRibeiro10/BCMIC-PHD.git",
"svn_url": "https://github.com/AngelRibeiro10/BCMIC-PHD",
"homepage": null,
"size": 69612,
"stargazers_count": 0,
"watchers_count": 0,
"language": null,
"has_issues": true,
"has_projects": true,
"has_downloads": true,
"has_wiki": true,
"has_pages": false,
"forks_count": 0,
"mirror_url": null,
"archived": false,
"disabled": false,
"open_issues_count": 0,
"license": {
"key": "apache-2.0",
"name": "Apache License 2.0",
"spdx_id": "Apache-2.0",
"url": "https://api.github.com/licenses/apache-2.0",
"node_id": "MDc6TGljZW5zZTI="
},
"forks": 0,
"open_issues": 0,
"watchers": 0,
"default_branch": "master",
"temp_clone_token": null,
"network_count": 0,
"subscribers_count": 1
}
I want to get this picture of 'Social Preview' ... but it doent show in the returning of the project atributes.
Thank you very much :)
So it's not possible to retrieve it from the API, but in my case since I only displayed my top three repos on my website it wasn't a pain to manually grab the image URLs.
I did this by uploading the preview image on GitHub, then right click on the image when it pops up -> inspect and you'll see in the developer tools the element has a 'background-image: url()' property, right click on that URL and then open in new tab, and there's the URL for your image!
Like I said, it's a manual process but if you need to only do it a few times then it's not a huge deal. That was my workaround.

Outlook MAPI Message Class Metadata in Outlook 2016

I've been looking all over and I can't seem to find anywhere that MS has this information documented. (This includes the MS documentation on MAPI message classes. This Super User answer elucidates what seems to be all of the standard Message Classes that are possible, but I haven't been able to find a list of the possible metadata that are associated with the Message Classes.
Does anyone know where I can find the metadata for each of the Message Classes as well as a possible brief (or detailed!) description of what the column means? Some of them are pretty obvious ("ReceivedDate", Start, etc.) but others are less obvious.
I've munged around with PowerShell and managed to find the following:
Schedule Meeting Request:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies ",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AutoForwarded",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest ",
"FlagStatus",
"OriginatorDeliveryReportRequested",
"ReceivedTime",
"Recipients",
"ReminderSet",
"ReminderTime",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"Submitted",
"Links",
"DownloadState",
"ItemProperties",
"MarkForDownload",
"IsConflict",
"MeetingWorkspaceURL",
"FlagIcon",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"PropertyAccessor",
"ConversationID",
"SendUsingAccount",
"IsLatestVersion",
"RTFBody",
"RetentionExpirationDate",
"RetentionPolicyName",
"BodyFormat"
RSS:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"ExpiryTime",
"HTMLBody",
"ReceivedTime",
"SenderName",
"SentOn",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"PropertyAccessor",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"IsMarkedAsTask",
"ConversationID",
"RTFBody"
Notes:
"Application",
"Class",
"Session",
"Parent",
"Body",
"Categories",
"Color",
"CreationTime",
"EntryID",
"GetInspector",
"Height",
"LastModificationTime",
"Left",
"MessageClass",
"Saved",
"Size",
"Subject",
"Top",
"Width",
"Links",
"DownloadState",
"ItemProperties",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor"
Contact:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"Account",
"Anniversary",
"AssistantName",
"AssistantTelephoneNumber",
"Birthday",
"Business2TelephoneNumber",
"BusinessAddress",
"BusinessAddressCity",
"BusinessAddressCountry",
"BusinessAddressPostalCode",
"BusinessAddressPostOfficeBox",
"BusinessAddressState",
"BusinessAddressStreet",
"BusinessFaxNumber",
"BusinessHomePage",
"BusinessTelephoneNumber",
"CallbackTelephoneNumber",
"CarTelephoneNumber",
"Children",
"CompanyAndFullName",
"CompanyLastFirstNoSpace",
"CompanyLastFirstSpaceOnly",
"CompanyMainTelephoneNumber",
"CompanyName",
"ComputerNetworkName",
"CustomerID",
"Department",
"Email1Address",
"Email1AddressType",
"Email1DisplayName",
"Email1EntryID",
"Email2Address",
"Email2AddressType",
"Email2DisplayName",
"Email2EntryID",
"Email3Address",
"Email3AddressType",
"Email3DisplayName",
"Email3EntryID",
"FileAs",
"FirstName",
"FTPSite",
"FullName",
"FullNameAndCompany",
"Gender",
"GovernmentIDNumber",
"Hobby",
"Home2TelephoneNumber",
"HomeAddress",
"HomeAddressCity",
"HomeAddressCountry",
"HomeAddressPostalCode",
"HomeAddressPostOfficeBox",
"HomeAddressState",
"HomeAddressStreet",
"HomeFaxNumber",
"HomeTelephoneNumber",
"Initials",
"InternetFreeBusyAddress",
"ISDNNumber",
"JobTitle",
"Journal",
"Language",
"LastFirstAndSuffix",
"LastFirstNoSpace",
"LastFirstNoSpaceCompany",
"LastFirstSpaceOnly",
"LastFirstSpaceOnlyCompany",
"LastName",
"LastNameAndFirstName",
"MailingAddress",
"MailingAddressCity",
"MailingAddressCountry",
"MailingAddressPostalCode",
"MailingAddressPostOfficeBox",
"MailingAddressState",
"MailingAddressStreet",
"ManagerName",
"MiddleName",
"MobileTelephoneNumber",
"NetMeetingAlias",
"NetMeetingServer",
"NickName",
"OfficeLocation",
"OrganizationalIDNumber",
"OtherAddress",
"OtherAddressCity",
"OtherAddressCountry",
"OtherAddressPostalCode",
"OtherAddressPostOfficeBox",
"OtherAddressState",
"OtherAddressStreet",
"OtherFaxNumber",
"OtherTelephoneNumber",
"PagerNumber",
"PersonalHomePage",
"PrimaryTelephoneNumber",
"Profession",
"RadioTelephoneNumber",
"ReferredBy",
"SelectedMailingAddress",
"Spouse",
"Suffix",
"TelexNumber",
"Title",
"TTYTDDTelephoneNumber",
"User1",
"User2",
"User3",
"User4",
"UserCertificate",
"WebPage",
"YomiCompanyName",
"YomiFirstName",
"YomiLastName",
"Links",
"ItemProperties",
"LastFirstNoSpaceAndSuffix",
"DownloadState",
"IMAddress",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"HasPicture",
"PropertyAccessor",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"IsMarkedAsTask",
"BusinessCardLayoutXml",
"BusinessCardType",
"ConversationID",
"RTFBody"
Conversations:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AlternateRecipientAllowed",
"AutoForwarded",
"BCC",
"CC",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest",
"FlagStatus",
"HTMLBody",
"OriginatorDeliveryReportRequested",
"ReadReceiptRequested",
"ReceivedByEntryID",
"ReceivedByName",
"ReceivedOnBehalfOfEntryID",
"ReceivedOnBehalfOfName",
"ReceivedTime",
"RecipientReassignmentProhibited",
"Recipients",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"RemoteStatus",
"ReplyRecipientNames",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"SentOnBehalfOfName",
"Submitted",
"[To]",
"VotingOptions",
"VotingResponse",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"IsIPFax",
"FlagIcon",
"HasCoverSheet",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"EnableSharedAttachments",
"Permission",
"PermissionService",
"PropertyAccessor",
"SendUsingAccount",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"IsMarkedAsTask",
"ConversationID",
"Sender",
"PermissionTemplateGuid",
"RTFBody",
"RetentionPolicyName",
"RetentionExpirationDate"
Tasks:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"ActualWork",
"CardData",
"Complete",
"Contacts",
"ContactNames",
"DateCompleted",
"DelegationState",
"Delegator",
"DueDate",
"IsRecurring",
"Ordinal",
"Owner",
"Ownership",
"PercentComplete",
"Recipients",
"ReminderTime",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ResponseState",
"Role",
"SchedulePlusPriority",
"StartDate",
"Status",
"StatusOnCompletionRecipients",
"StatusUpdateRecipients",
"TeamTask",
"TotalWork",
"Links",
"DownloadState",
"ItemProperties",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor",
"SendUsingAccount",
"ToDoTaskOrdinal",
"ConversationID",
"RTFBody",
Calendar:
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AllDayEvent",
"BusyStatus",
"Duration",
"End",
"IsOnlineMeeting",
"IsRecurring",
"Location",
"MeetingStatus",
"NetMeetingAutoStart",
"NetMeetingOrganizerAlias",
"NetMeetingServer",
"NetMeetingType",
"OptionalAttendees",
"Organizer",
"Recipients",
"RecurrenceState",
"ReminderMinutesBeforeStart",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReplyTime",
"RequiredAttendees",
"Resources",
"ResponseRequested",
"ResponseStatus",
"Start",
"NetMeetingDocPathName",
"NetShowURL",
"Links",
"ConferenceServerAllowExternal",
"ConferenceServerPassword",
"ItemProperties",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"MeetingWorkspaceURL",
"AutoResolvedWinner",
"Conflicts",
"PropertyAccessor",
"SendUsingAccount",
"GlobalAppointmentID",
"ForceUpdateToAllAttendees",
"StartUTC",
"EndUTC",
"StartInStartTimeZone",
"EndInEndTimeZone",
"StartTimeZone",
"EndTimeZone",
"ConversationID",
"RTFBody",
"BodyFormat"
e-mail (IPM.Note):
"Application",
"Class",
"Session",
"Parent",
"Actions",
"Attachments",
"BillingInformation",
"Body",
"Categories",
"Companies",
"ConversationIndex",
"ConversationTopic",
"CreationTime",
"EntryID",
"FormDescription",
"GetInspector",
"Importance",
"LastModificationTime",
"MAPIOBJECT",
"MessageClass",
"Mileage",
"NoAging",
"OutlookInternalVersion",
"OutlookVersion",
"Saved",
"Sensitivity",
"Size",
"Subject",
"UnRead",
"UserProperties",
"AlternateRecipientAllowed",
"AutoForwarded",
"BCC",
"CC",
"DeferredDeliveryTime",
"DeleteAfterSubmit",
"ExpiryTime",
"FlagDueBy",
"FlagRequest",
"FlagStatus",
"HTMLBody",
"OriginatorDeliveryReportRequested",
"ReadReceiptRequested",
"ReceivedByEntryID",
"ReceivedByName",
"ReceivedOnBehalfOfEntryID",
"ReceivedOnBehalfOfName",
"ReceivedTime",
"RecipientReassignmentProhibited",
"Recipients",
"ReminderOverrideDefault",
"ReminderPlaySound",
"ReminderSet",
"ReminderSoundFile",
"ReminderTime",
"RemoteStatus",
"ReplyRecipientNames",
"ReplyRecipients",
"SaveSentMessageFolder",
"SenderName",
"Sent",
"SentOn",
"SentOnBehalfOfName",
"Submitted",
"[To]",
"VotingOptions",
"VotingResponse",
"Links",
"ItemProperties",
"BodyFormat",
"DownloadState",
"InternetCodepage",
"MarkForDownload",
"IsConflict",
"IsIPFax",
"FlagIcon",
"HasCoverSheet",
"AutoResolvedWinner",
"Conflicts",
"SenderEmailAddress",
"SenderEmailType",
"EnableSharedAttachments",
"Permission",
"PermissionService",
"PropertyAccessor",
"SendUsingAccount",
"TaskSubject",
"TaskDueDate",
"TaskStartDate",
"TaskCompletedDate",
"ToDoTaskOrdinal",
"IsMarkedAsTask",
"ConversationID",
"Sender",
"PermissionTemplateGuid",
"RTFBody",
"RetentionPolicyName",
"RetentionExpirationDate"
The Microsoft Outlook object browser displays the classes, properties, methods, and events available from the Outlook object library.
If you do not see the Developer tab, see Run in Developer Mode in Outlook to activate the Developer tab. On the Developer tab, in the Form group, click View Code to open the Script Editor. In the Script Editor, click Object Browser on the Script menu or press F2.
All of the available Outlook objects are listed in the Classes pane of the object browser in alphabetical order. To view the members of an object, select the object in the Classes pane. The members of this object appear in alphabetical order in the Members of pane. The heading at the top of this pane will reflect the name of the object that you select. For example, if you select the AppointmentItem object in the Classes pane, the heading of the Members of pane will appear as Members of AppointmentItem.
The interfaces and members of the Microsoft.Office.Interop.Outlook namespace that provide support for interoperability between the COM object model of Outlook and managed applications that automate Outlook are described here.

Verify a signature in JWT.IO

I have generated the following token and am trying to verify the signature with http://jwt.io
I have also attached the contents of my jwks endpoint that should have all the details I need to verify.
So my question is: how do I get this to say signature valid on the jwt.io website? Am I missing some transformation on the certificate chain parameter?
Here is the spec for jwks for reference.
eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSIsImtpZCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSJ9.eyJub25jZSI6IjYzNjA3MDM0OTc3NDIzODg2NS5OMlkxTldKbU1EZ3RZbU13TkMwME9XWTNMVGt5TlRJdE9ERXpOell4Wm1NME0yVmxNV1l5TkdOaFlXTXRaVEpqT1MwME4yRmpMVGd6WmpVdFpXWTVOVEEwWmpFMU1qWTEiLCJpYXQiOjE0NzE0MzgxODIsImF0X2hhc2giOiJLWUJpVkl1Uy1YZERzU3NHcWU5dTJBIiwic3ViIjoiMSIsImFtciI6InBhc3N3b3JkIiwiYXV0aF90aW1lIjoxNDcxNDM4MTgyLCJpZHAiOiJpZHNydiIsImlzcyI6Imh0dHBzOi8vZWx3ZWJhcHBsaWNhdGlvbjEuYXp1cmV3ZWJzaXRlcy5uZXQvaWRlbnRpdHkiLCJhdWQiOiJtdmMiLCJleHAiOjE0NzE0Mzg0ODIsIm5iZiI6MTQ3MTQzODE4Mn0.Ehck2-rA09cJzlfURhDMp-WcXm_t_dl-u0Mli3exdv1HxX8i77x5VfFPM6rP4lcpI3lpN8Yj-FefZYDTUY_UmxCYvXf6ILSrhzEfQVaXSPKX1RUQQIDJGPU6NuFLcR416JpUAkE8joYae3WPj5VsM4yNENGGjUANm4qgj6G_mYy_BiXcSqvRGRYwW5GHDsnnANrIw4oktIYS05yCbjdiNYgQZ043L6Pb2p-5eTPCFqG7WRHp208dhg8D3nhtYEov2Kxod93oKHXSp1zf-Ot0cadk6Ss4fClaTE9S1f29lbwxw7ZxI1L3R4oOL3FZPSSHGp4d3a3AdUKOjKvvTVPv6w
{
keys : [{
kty : "RSA",
use : "sig",
kid : "a3rMUgMFv9tPclLa6yF3zAkfquE",
x5t : "a3rMUgMFv9tPclLa6yF3zAkfquE",
e : "AQAB",
n : "qnTksBdxOiOlsmRNd-mMS2M3o1IDpK4uAr0T4_YqO3zYHAGAWTwsq4ms-NWynqY5HaB4EThNxuq2GWC5JKpO1YirOrwS97B5x9LJyHXPsdJcSikEI9BxOkl6WLQ0UzPxHdYTLpR4_O-0ILAlXw8NU4-jB4AP8Sn9YGYJ5w0fLw5YmWioXeWvocz1wHrZdJPxS8XnqHXwMUozVzQj-x6daOv5FmrHU1r9_bbp0a1GLv4BbTtSh4kMyz1hXylho0EvPg5p9YIKStbNAW9eNWvv5R8HN7PPei21AsUqxekK0oW9jnEdHewckToX7x5zULWKwwZIksll0XnVczVgy7fCFw",
x5c : [
"MIIDBTCCAfGgAwIBAgIQNQb+T2ncIrNA6cKvUA1GWTAJBgUrDgMCHQUAMBIxEDAOBgNVBAMTB0RldlJvb3QwHhcNMTAwMTIwMjIwMDAwWhcNMjAwMTIwMjIwMDAwWjAVMRMwEQYDVQQDEwppZHNydjN0ZXN0MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqnTksBdxOiOlsmRNd+mMS2M3o1IDpK4uAr0T4/YqO3zYHAGAWTwsq4ms+NWynqY5HaB4EThNxuq2GWC5JKpO1YirOrwS97B5x9LJyHXPsdJcSikEI9BxOkl6WLQ0UzPxHdYTLpR4/O+0ILAlXw8NU4+jB4AP8Sn9YGYJ5w0fLw5YmWioXeWvocz1wHrZdJPxS8XnqHXwMUozVzQj+x6daOv5FmrHU1r9/bbp0a1GLv4BbTtSh4kMyz1hXylho0EvPg5p9YIKStbNAW9eNWvv5R8HN7PPei21AsUqxekK0oW9jnEdHewckToX7x5zULWKwwZIksll0XnVczVgy7fCFwIDAQABo1wwWjATBgNVHSUEDDAKBggrBgEFBQcDATBDBgNVHQEEPDA6gBDSFgDaV+Q2d2191r6A38tBoRQwEjEQMA4GA1UEAxMHRGV2Um9vdIIQLFk7exPNg41NRNaeNu0I9jAJBgUrDgMCHQUAA4IBAQBUnMSZxY5xosMEW6Mz4WEAjNoNv2QvqNmk23RMZGMgr516ROeWS5D3RlTNyU8FkstNCC4maDM3E0Bi4bbzW3AwrpbluqtcyMN3Pivqdxx+zKWKiORJqqLIvN8CT1fVPxxXb/e9GOdaR8eXSmB0PgNUhM4IjgNkwBbvWC9F/lzvwjlQgciR7d4GfXPYsE1vf8tmdQaY8/PtdAkExmbrb9MihdggSoGXlELrPA91Yce+fiRcKY3rQlNWVd4DOoJ/cPXsXwry8pWjNCo5JD8Q+RQ5yZEy7YPoifwemLhTdsBz3hlZr28oCGJ3kbnpW0xGvQb3VHSTVVbeei0CfXoW6iz1"
]
}
]
}
jwt.io says to enter the key
Public Key or Certificate. Enter it in plain text only if you want to verify a token
so I have converted the JSON Web Key to a PEM format guessing it would need a base64 format, and it works!.
This is the public key built from modulus and exponent
-----BEGIN PUBLIC KEY-----
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAqnTksBdxOiOlsmRNd+mMS2M3o1IDpK4uAr0T4/YqO3zYHAGAWTwsq4ms+NWynqY5HaB4EThNxuq2GWC5JKpO1YirOrwS97B5x9LJyHXPsdJcSikEI9BxOkl6WLQ0UzPxHdYTLpR4/O+0ILAlXw8NU4+jB4AP8Sn9YGYJ5w0fLw5YmWioXeWvocz1wHrZdJPxS8XnqHXwMUozVzQj+x6daOv5FmrHU1r9/bbp0a1GLv4BbTtSh4kMyz1hXylho0EvPg5p9YIKStbNAW9eNWvv5R8HN7PPei21AsUqxekK0oW9jnEdHewckToX7x5zULWKwwZIksll0XnVczVgy7fCFwIDAQAB
-----END PUBLIC KEY-----
After some attemps I decided to write a simple test program to check if JWT signature is correct or it was a key format issue. You can test it (Java 8). It is fully functional
package test;
import java.math.BigInteger;
import java.security.InvalidKeyException;
import java.security.KeyFactory;
import java.security.NoSuchAlgorithmException;
import java.security.NoSuchProviderException;
import java.security.PublicKey;
import java.security.Signature;
import java.security.SignatureException;
import java.security.spec.InvalidKeySpecException;
import java.security.spec.RSAPublicKeySpec;
import java.util.Base64;
public class JWKTest {
private static final String[] HEX_TABLE = new String[]{
"00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "0a", "0b", "0c", "0d", "0e", "0f",
"10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "1a", "1b", "1c", "1d", "1e", "1f",
"20", "21", "22", "23", "24", "25", "26", "27", "28", "29", "2a", "2b", "2c", "2d", "2e", "2f",
"30", "31", "32", "33", "34", "35", "36", "37", "38", "39", "3a", "3b", "3c", "3d", "3e", "3f",
"40", "41", "42", "43", "44", "45", "46", "47", "48", "49", "4a", "4b", "4c", "4d", "4e", "4f",
"50", "51", "52", "53", "54", "55", "56", "57", "58", "59", "5a", "5b", "5c", "5d", "5e", "5f",
"60", "61", "62", "63", "64", "65", "66", "67", "68", "69", "6a", "6b", "6c", "6d", "6e", "6f",
"70", "71", "72", "73", "74", "75", "76", "77", "78", "79", "7a", "7b", "7c", "7d", "7e", "7f",
"80", "81", "82", "83", "84", "85", "86", "87", "88", "89", "8a", "8b", "8c", "8d", "8e", "8f",
"90", "91", "92", "93", "94", "95", "96", "97", "98", "99", "9a", "9b", "9c", "9d", "9e", "9f",
"a0", "a1", "a2", "a3", "a4", "a5", "a6", "a7", "a8", "a9", "aa", "ab", "ac", "ad", "ae", "af",
"b0", "b1", "b2", "b3", "b4", "b5", "b6", "b7", "b8", "b9", "ba", "bb", "bc", "bd", "be", "bf",
"c0", "c1", "c2", "c3", "c4", "c5", "c6", "c7", "c8", "c9", "ca", "cb", "cc", "cd", "ce", "cf",
"d0", "d1", "d2", "d3", "d4", "d5", "d6", "d7", "d8", "d9", "da", "db", "dc", "dd", "de", "df",
"e0", "e1", "e2", "e3", "e4", "e5", "e6", "e7", "e8", "e9", "ea", "eb", "ec", "ed", "ee", "ef",
"f0", "f1", "f2", "f3", "f4", "f5", "f6", "f7", "f8", "f9", "fa", "fb", "fc", "fd", "fe", "ff",
};
public static String toHexFromBytes(byte[] bytes) {
StringBuffer rc = new StringBuffer(bytes.length * 2);
for (int i = 0; i < bytes.length; i++) {
rc.append(HEX_TABLE[0xFF & bytes[i]]);
}
return rc.toString();
}
// Build the public key from modulus and exponent
public static PublicKey getPublicKey (String modulusB64u, String exponentB64u) throws NoSuchAlgorithmException, InvalidKeySpecException{
//conversion to BigInteger. I have transformed to Hex because new BigDecimal(byte) does not work for me
byte exponentB[] = Base64.getUrlDecoder().decode(exponentB64u);
byte modulusB[] = Base64.getUrlDecoder().decode(modulusB64u);
BigInteger exponent = new BigInteger(toHexFromBytes(exponentB), 16);
BigInteger modulus = new BigInteger(toHexFromBytes(modulusB), 16);
//Build the public key
RSAPublicKeySpec spec = new RSAPublicKeySpec(modulus, exponent);
KeyFactory factory = KeyFactory.getInstance("RSA");
PublicKey pub = factory.generatePublic(spec);
return pub;
}
public final static void main (String argv[]) throws NoSuchAlgorithmException, InvalidKeySpecException, SignatureException, NoSuchProviderException, InvalidKeyException{
String exponentB64u = "AQAB";
String modulusB64u = "qnTksBdxOiOlsmRNd-mMS2M3o1IDpK4uAr0T4_YqO3zYHAGAWTwsq4ms-NWynqY5HaB4EThNxuq2GWC5JKpO1YirOrwS97B5x9LJyHXPsdJcSikEI9BxOkl6WLQ0UzPxHdYTLpR4_O-0ILAlXw8NU4-jB4AP8Sn9YGYJ5w0fLw5YmWioXeWvocz1wHrZdJPxS8XnqHXwMUozVzQj-x6daOv5FmrHU1r9_bbp0a1GLv4BbTtSh4kMyz1hXylho0EvPg5p9YIKStbNAW9eNWvv5R8HN7PPei21AsUqxekK0oW9jnEdHewckToX7x5zULWKwwZIksll0XnVczVgy7fCFw";
String jwt = "eyJ0eXAiOiJKV1QiLCJhbGciOiJSUzI1NiIsIng1dCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSIsImtpZCI6ImEzck1VZ01Gdjl0UGNsTGE2eUYzekFrZnF1RSJ9.eyJub25jZSI6IjYzNjA3MDM0OTc3NDIzODg2NS5OMlkxTldKbU1EZ3RZbU13TkMwME9XWTNMVGt5TlRJdE9ERXpOell4Wm1NME0yVmxNV1l5TkdOaFlXTXRaVEpqT1MwME4yRmpMVGd6WmpVdFpXWTVOVEEwWmpFMU1qWTEiLCJpYXQiOjE0NzE0MzgxODIsImF0X2hhc2giOiJLWUJpVkl1Uy1YZERzU3NHcWU5dTJBIiwic3ViIjoiMSIsImFtciI6InBhc3N3b3JkIiwiYXV0aF90aW1lIjoxNDcxNDM4MTgyLCJpZHAiOiJpZHNydiIsImlzcyI6Imh0dHBzOi8vZWx3ZWJhcHBsaWNhdGlvbjEuYXp1cmV3ZWJzaXRlcy5uZXQvaWRlbnRpdHkiLCJhdWQiOiJtdmMiLCJleHAiOjE0NzE0Mzg0ODIsIm5iZiI6MTQ3MTQzODE4Mn0.Ehck2-rA09cJzlfURhDMp-WcXm_t_dl-u0Mli3exdv1HxX8i77x5VfFPM6rP4lcpI3lpN8Yj-FefZYDTUY_UmxCYvXf6ILSrhzEfQVaXSPKX1RUQQIDJGPU6NuFLcR416JpUAkE8joYae3WPj5VsM4yNENGGjUANm4qgj6G_mYy_BiXcSqvRGRYwW5GHDsnnANrIw4oktIYS05yCbjdiNYgQZ043L6Pb2p-5eTPCFqG7WRHp208dhg8D3nhtYEov2Kxod93oKHXSp1zf-Ot0cadk6Ss4fClaTE9S1f29lbwxw7ZxI1L3R4oOL3FZPSSHGp4d3a3AdUKOjKvvTVPv6w";
//Build the public key from modulus and exponent
PublicKey publicKey = getPublicKey (modulusB64u,exponentB64u);
//print key as PEM (base64 and headers)
String publicKeyPEM =
"-----BEGIN PUBLIC KEY-----\n"
+ Base64.getEncoder().encodeToString(publicKey.getEncoded()) +"\n"
+ "-----END PUBLIC KEY-----";
System.out.println( publicKeyPEM);
//get signed data and signature from JWT
String signedData = jwt.substring(0, jwt.lastIndexOf("."));
String signatureB64u = jwt.substring(jwt.lastIndexOf(".")+1,jwt.length());
byte signature[] = Base64.getUrlDecoder().decode(signatureB64u);
//verify Signature
Signature sig = Signature.getInstance("SHA256withRSA");
sig.initVerify(publicKey);
sig.update(signedData.getBytes());
boolean v = sig.verify(signature);
System.out.println(v);
}
}