Skip to content

Commit abaab76

Browse files
JMouniertux3
authored andcommitted
feat(oidc): add OidcAutorizationCodeVerification
1 parent 5ed8c2f commit abaab76

3 files changed

Lines changed: 40 additions & 1 deletion

File tree

cffi_defs.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -224,6 +224,7 @@ enum tanker_verification_method_type
224224
TANKER_VERIFICATION_METHOD_PREVERIFIED_PHONE_NUMBER,
225225
TANKER_VERIFICATION_METHOD_E2E_PASSPHRASE,
226226
TANKER_VERIFICATION_METHOD_PREVERIFIED_OIDC,
227+
TANKER_VERIFICATION_METHOD_OIDC_AUTHORIZATION_CODE,
227228

228229
TANKER_VERIFICATION_METHOD_LAST
229230
};
@@ -241,6 +242,7 @@ typedef struct tanker_options tanker_options_t;
241242
typedef struct tanker_email_verification tanker_email_verification_t;
242243
typedef struct tanker_phone_number_verification tanker_phone_number_verification_t;
243244
typedef struct tanker_preverified_oidc_verification tanker_preverified_oidc_verification_t;
245+
typedef struct tanker_oidc_authorization_code_verification tanker_oidc_authorization_code_verification_t;
244246
typedef struct tanker_verification tanker_verification_t;
245247
typedef struct tanker_verification_list tanker_verification_list_t;
246248
typedef struct tanker_verification_method tanker_verification_method_t;
@@ -314,6 +316,14 @@ struct tanker_preverified_oidc_verification
314316
char const* provider_id;
315317
};
316318

319+
struct tanker_oidc_authorization_code_verification
320+
{
321+
uint8_t version;
322+
char const* provider_id;
323+
char const* authorization_code;
324+
char const* state;
325+
};
326+
317327
struct tanker_verification
318328
{
319329
uint8_t version;
@@ -329,6 +339,7 @@ struct tanker_verification
329339
char const* preverified_email;
330340
char const* preverified_phone_number;
331341
tanker_preverified_oidc_verification_t preverified_oidc_verification;
342+
tanker_oidc_authorization_code_verification_t oidc_authorization_code_verification;
332343
};
333344

334345
struct tanker_verification_method
@@ -450,6 +461,8 @@ tanker_future_t* tanker_attach_provisional_identity(
450461
tanker_future_t* tanker_verify_provisional_identity(
451462
tanker_t* ctanker, tanker_verification_t const* verification);
452463

464+
tanker_expected_t* tanker_authenticate_with_idp(tanker_t* session, char const* provider_id, char const* cookie);
465+
453466
void tanker_free_buffer(void const* buffer);
454467

455468
void tanker_free_verification_method_list(

tankersdk/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
EmailVerification,
1717
EmailVerificationMethod,
1818
EncryptionOptions,
19+
OidcAuthorizationCodeVerification,
1920
OidcIdTokenVerification,
2021
OidcIdTokenVerificationMethod,
2122
Padding,

tankersdk/tanker.py

Lines changed: 26 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ class VerificationMethodType(Enum):
6363
PREVERIFIED_PHONE_NUMBER = 7
6464
E2E_PASSPHRASE = 8
6565
PREVERIFIED_OIDC = 9
66+
OIDC_AUTHORIZATION_CODE = 10
6667

6768

6869
class Verification:
@@ -148,6 +149,15 @@ def __init__(self, subject: str, provider_id: str):
148149
self.provider_id = provider_id
149150

150151

152+
class OidcAuthorizationCodeVerification(Verification):
153+
method_type = VerificationMethodType.OIDC_AUTHORIZATION_CODE
154+
155+
def __init__(self, provider_id: str, authorization_code: str, state: str):
156+
self.provider_id = provider_id
157+
self.authorization_code = authorization_code
158+
self.state = state
159+
160+
151161
class VerificationMethod:
152162
# Note: we want every subclass to have a 'mehod_type' attribute
153163
# of type VerificationMethodType, but there's no "good"
@@ -390,7 +400,7 @@ def __init__(
390400

391401
# Note: we store things in `self` so they don't get
392402
# garbage collected later on
393-
c_verification = ffi.new("tanker_verification_t *", {"version": 7})
403+
c_verification = ffi.new("tanker_verification_t *", {"version": 8})
394404
if isinstance(verification, VerificationKeyVerification):
395405
c_verification.verification_method_type = (
396406
tankerlib.TANKER_VERIFICATION_METHOD_VERIFICATION_KEY
@@ -479,6 +489,21 @@ def __init__(
479489
c_verification.preverified_oidc_verification = (
480490
self._preverified_oidc_verification
481491
)
492+
elif isinstance(verification, OidcAuthorizationCodeVerification):
493+
c_verification.verification_method_type = (
494+
tankerlib.TANKER_VERIFICATION_METHOD_OIDC_AUTHORIZATION_CODE
495+
)
496+
self._oidc_authorization_code_verification = {
497+
"version": 1,
498+
"provider_id": ffihelpers.str_to_c_string(verification.provider_id),
499+
"authorization_code": ffihelpers.str_to_c_string(
500+
verification.authorization_code
501+
),
502+
"state": ffihelpers.str_to_c_string(verification.state),
503+
}
504+
c_verification.oidc_authorization_code_verification = (
505+
self._oidc_authorization_code_verification
506+
)
482507

483508
self._c_verification = c_verification
484509

0 commit comments

Comments
 (0)