Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.
Hi,
I am trying to implement OAuth2 in custom connector. I should pass code_challenge_method with a value plain or SHA256. Does Power Query has an function to do the hashing? Because how I understand pass plain value, not suggested.
"Method used to generate the challenge (e.g., S256). The PKCE spec defines two methods, S256 and plain, the former is used in this example and is the only one supported by Auth0 since the latter is discouraged."
Solved! Go to Solution.
You should be able to find what you need in the CryptoAlgorithm.* library. Note this library is only avialable to connectors.
E.g.
Binary.ToText(Crypto.CreateHash(CryptoAlgorithm.SHA256, Text.ToBinary(str, TextEncoding.Ascii)), BinaryEncoding.Base64)
Actually see if this works:
Base64UrlEncodeWithoutPadding = (hash as binary) as text =>
let
base64Encoded = Binary.ToText(hash, BinaryEncoding.Base64),
base64UrlEncoded = Text.Replace(Text.Replace(base64Encoded, "+", "-"), "/", "_"),
withoutPadding = Text.TrimEnd(base64UrlEncoded, "=")
in
withoutPadding;
MyConnector.StartLogin = (resourceUrl, state, display) =>
let
baseUri = ..., //Generate uri from resourceUrl
codeVerifier = Text.NewGuid() & Text.NewGuid(),
codeChallenge = Base64UrlEncodeWithoutPadding(Crypto.CreateHash(CryptoAlgorithm.SHA256, Text.ToBinary(codeVerifier, TextEncoding.Ascii))),
authorizeUrl = baseUri & "/oauth2/authorize?" & Uri.BuildQueryString([
client_id = clientId,
scope = tokenScope,
state = state,
code_challenge_method = "S256",
code_challenge = codeChallenge,
redirect_uri = redirectUri,
response_type = "code"])
in
[
LoginUri = authorizeUrl,
CallbackUri = redirectUri,
WindowHeight = 720,
WindowWidth = 1024,
Context = [BaseUri = baseUri, CodeVerifier = codeVerifier]
];
You should be able to find what you need in the CryptoAlgorithm.* library. Note this library is only avialable to connectors.
E.g.
Binary.ToText(Crypto.CreateHash(CryptoAlgorithm.SHA256, Text.ToBinary(str, TextEncoding.Ascii)), BinaryEncoding.Base64)
thanks...@artemus and how generate, before hashing, high-entropy random string called code_verifier-
This is a cryptographically random string using the characters A-Z, a-z, 0-9, and the punctuation characters -._~ (hyphen, period, underscore, and tilde), between 43 and 128 characters long.
Actually see if this works:
Base64UrlEncodeWithoutPadding = (hash as binary) as text =>
let
base64Encoded = Binary.ToText(hash, BinaryEncoding.Base64),
base64UrlEncoded = Text.Replace(Text.Replace(base64Encoded, "+", "-"), "/", "_"),
withoutPadding = Text.TrimEnd(base64UrlEncoded, "=")
in
withoutPadding;
MyConnector.StartLogin = (resourceUrl, state, display) =>
let
baseUri = ..., //Generate uri from resourceUrl
codeVerifier = Text.NewGuid() & Text.NewGuid(),
codeChallenge = Base64UrlEncodeWithoutPadding(Crypto.CreateHash(CryptoAlgorithm.SHA256, Text.ToBinary(codeVerifier, TextEncoding.Ascii))),
authorizeUrl = baseUri & "/oauth2/authorize?" & Uri.BuildQueryString([
client_id = clientId,
scope = tokenScope,
state = state,
code_challenge_method = "S256",
code_challenge = codeChallenge,
redirect_uri = redirectUri,
response_type = "code"])
in
[
LoginUri = authorizeUrl,
CallbackUri = redirectUri,
WindowHeight = 720,
WindowWidth = 1024,
Context = [BaseUri = baseUri, CodeVerifier = codeVerifier]
];
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
102 | |
53 | |
21 | |
13 | |
11 |