目的のメカニズムを(サーバがサポートしているものから)選択した後、認証要求パケットを作成し、それをサーバーに送信する必要があります。次のパケットは、パスワードが"bar"で、"foo"のPLAIN認証を使用したパケットを示しています。
Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 80 | 21 ('!') | 00 | 05 | +---------------+---------------+---------------+---------------+ 4| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 8| 00 | 00 | 00 | 10 | +---------------+---------------+---------------+---------------+ 12| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 16| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 20| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 24| 50 ('P') | 4c ('L') | 41 ('A') | 49 ('I') | +---------------+---------------+---------------+---------------+ 28| 4e ('N') | 66 ('f') | 6f ('o') | 6f ('o') | +---------------+---------------+---------------+---------------+ 32| 00 | 66 ('f') | 6f ('o') | 6f ('o') | +---------------+---------------+---------------+---------------+ 36| 00 | 62 ('b') | 61 ('a') | 72 ('r') |
Header breakdown Field (offset) (value) Magic (0): 0x80 (PROTOCOL_BINARY_REQ) Opcode (1): 0x21 (sasl auth) Key length (2-3): 0x0005 (5) Extra length (4): 0x00 Data type (5): 0x00 vBucket (6-7): 0x0000 (0) Total body (8-11): 0x00000010 (16) Opaque (12-15): 0x00000000 (0) CAS (16-23): 0x0000000000000000 (0) Mechanisms (24-28): PLAIN Auth token (29-39): foo0x00foo0x00bar
サーバがこのユーザ名/パスワードの組み合わせを受け入れた場合、2つのステータスコード:"Success"または"Authentication Continuation"(認証の継続)を返します。Successは、この作業が終わることを意味します。
Byte/ 0 | 1 | 2 | 3 | / | | | | |0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7|0 1 2 3 4 5 6 7| +---------------+---------------+---------------+---------------+ 0| 81 | 21 ('!') | 00 | 00 | +---------------+---------------+---------------+---------------+ 4| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 8| 00 | 00 | 00 | 0d | +---------------+---------------+---------------+---------------+ 12| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 16| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 20| 00 | 00 | 00 | 00 | +---------------+---------------+---------------+---------------+ 24| 41 ('A') | 75 ('u') | 74 ('t') | 68 ('h') | +---------------+---------------+---------------+---------------+ 28| 65 ('e') | 6e ('n') | 74 ('t') | 69 ('i') | +---------------+---------------+---------------+---------------+ 32| 63 ('c') | 61 ('a') | 74 ('t') | 65 ('e') | +---------------+---------------+---------------+---------------+ 36| 64 ('d') |
Header breakdown Field (offset) (value) Magic (0): 0x81 (PROTOCOL_BINARY_RES) Opcode (1): 0x21 (sasl auth) Key length (2-3): 0x0000 (0) Extra length (4): 0x00 Data type (5): 0x00 Status (6-7): 0x0000 (SUCCESS) Total body (8-11): 0x0000000d (13) Opaque (12-15): 0x00000000 (0) CAS (16-23): 0x0000000000000000 (0) Info (24-36): Authenticated